🎇 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" "path/filepath"
) )
type GoogleDrive struct {} type GoogleDrive struct{}
var driverName = "GoogleDrive" 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) { 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 { if err != nil {
return "", err 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) link := fmt.Sprintf("https://www.googleapis.com/drive/v3/files/%s?includeItemsFromAllDrives=true&supportsAllDrives=true", file.Id)
var e GoogleError var e GoogleError
_, _ = googleClient.R().SetError(&e). _, _ = 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) { func (driver GoogleDrive) Preview(path string, account *model.Account) (interface{}, error) {
return nil, nil return nil, nil
} }

View File

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