From c39752ceb4cbc6249b641415d63296424e3de3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Sat, 27 Nov 2021 20:40:03 +0800 Subject: [PATCH] :sparkler: optimization googledrive --- drivers/googledrive/driver.go | 9 ++++--- drivers/googledrive/googledrive.go | 40 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/drivers/googledrive/driver.go b/drivers/googledrive/driver.go index 8e646fd4..36f962d7 100644 --- a/drivers/googledrive/driver.go +++ b/drivers/googledrive/driver.go @@ -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 -} \ No newline at end of file +} diff --git a/drivers/googledrive/googledrive.go b/drivers/googledrive/googledrive.go index 729f88d4..413e48bd 100644 --- a/drivers/googledrive/googledrive.go +++ b/drivers/googledrive/googledrive.go @@ -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)