🎇 optimization googledrive

pull/548/head
微凉 2021-11-27 20:40:03 +08:00
parent 53b383d2cf
commit c39752ceb4
2 changed files with 26 additions and 23 deletions

View File

@ -11,7 +11,7 @@ import (
"path/filepath"
)
type GoogleDrive struct {}
type GoogleDrive struct{}
var driverName = "GoogleDrive"
@ -109,10 +109,13 @@ func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.Fi
}
func (driver GoogleDrive) Link(path string, account *model.Account) (string, error) {
file, err := driver.GetFile(utils.ParsePath(path), account)
file, err := driver.File(path, account)
if err != nil {
return "", err
}
if file.Type == conf.FOLDER {
return "", drivers.NotFile
}
link := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.Id)
var e GoogleError
_, _ = googleClient.R().SetError(&e).
@ -156,4 +159,4 @@ func (driver GoogleDrive) Proxy(c *gin.Context, account *model.Account) {
func (driver GoogleDrive) Preview(path string, account *model.Account) (interface{}, error) {
return nil, nil
}
}

View File

@ -131,26 +131,26 @@ func (driver GoogleDrive) GetFiles(id string, account *model.Account) ([]GoogleF
return res, nil
}
func (driver GoogleDrive) GetFile(path string, account *model.Account) (*GoogleFile, error) {
dir, name := filepath.Split(path)
dir = utils.ParsePath(dir)
_, _, err := driver.Path(dir, account)
if err != nil {
return nil, err
}
parentFiles_, _ := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, dir))
parentFiles, _ := parentFiles_.([]GoogleFile)
for _, file := range parentFiles {
if file.Name == name {
if !driver.IsDir(file.MimeType) {
return &file, err
} else {
return nil, fmt.Errorf("not file")
}
}
}
return nil, fmt.Errorf("path not found")
}
//func (driver GoogleDrive) GetFile(path string, account *model.Account) (*GoogleFile, error) {
// dir, name := filepath.Split(path)
// dir = utils.ParsePath(dir)
// _, _, err := driver.Path(dir, account)
// if err != nil {
// return nil, err
// }
// parentFiles_, _ := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, dir))
// parentFiles, _ := parentFiles_.([]GoogleFile)
// for _, file := range parentFiles {
// if file.Name == name {
// if !driver.IsDir(file.MimeType) {
// return &file, err
// } else {
// return nil, drivers.NotFile
// }
// }
// }
// return nil, drivers.PathNotFound
//}
var _ drivers.Driver = (*GoogleDrive)(nil)