mirror of https://github.com/Xhofe/alist
🎇 optimization googledrive
parent
53b383d2cf
commit
c39752ceb4
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue