🎨 abstract cache method

pull/548/head
微凉 2021-12-08 22:58:44 +08:00
parent bb6e520ab5
commit b36eaf08f0
8 changed files with 18 additions and 19 deletions

View File

@ -129,7 +129,7 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
if err != nil {
return nil, err
}
parentFiles_, _ := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, dir))
parentFiles_, _ := base.GetCache(dir, account)
parentFiles, _ := parentFiles_.([]Pan123File)
for _, file := range parentFiles {
if file.FileName == name {

View File

@ -12,11 +12,11 @@ import (
"path/filepath"
)
type Pan123 struct {}
type Pan123 struct{}
func (driver Pan123) Config() base.DriverConfig {
return base.DriverConfig{
Name: "123Pan",
Name: "123Pan",
OnlyProxy: false,
}
}
@ -96,7 +96,7 @@ func (driver Pan123) File(path string, account *model.Account) (*model.File, err
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path)
var rawFiles []Pan123File
cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path))
cache, err := base.GetCache(path, account)
if err == nil {
rawFiles, _ = cache.([]Pan123File)
} else {
@ -109,7 +109,7 @@ func (driver Pan123) Files(path string, account *model.Account) ([]model.File, e
return nil, err
}
if len(rawFiles) > 0 {
_ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), rawFiles, nil)
_ = base.SetCache(path, rawFiles, account)
}
}
files := make([]model.File, 0)
@ -148,11 +148,11 @@ func (driver Pan123) Link(path string, account *model.Account) (string, error) {
}
return "", fmt.Errorf(resp.Message)
}
u,err := url.Parse(resp.Data.DownloadUrl)
u, err := url.Parse(resp.Data.DownloadUrl)
if err != nil {
return "", err
}
u_ := fmt.Sprintf("https://%s%s",u.Host,u.Path)
u_ := fmt.Sprintf("https://%s%s", u.Host, u.Path)
res, err := base.NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_)
if err != nil {
return "", err
@ -210,4 +210,4 @@ func (driver Pan123) Upload(file *model.FileStream, account *model.Account) erro
return base.ErrNotImplement
}
var _ base.Driver = (*Pan123)(nil)
var _ base.Driver = (*Pan123)(nil)

View File

@ -104,7 +104,7 @@ func (driver Cloud189) File(path string, account *model.Account) (*model.File, e
func (driver Cloud189) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path)
var rawFiles []Cloud189File
cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path))
cache, err := base.GetCache(path, account)
if err == nil {
rawFiles, _ = cache.([]Cloud189File)
} else {
@ -117,7 +117,7 @@ func (driver Cloud189) Files(path string, account *model.Account) ([]model.File,
return nil, err
}
if len(rawFiles) > 0 {
_ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), rawFiles, nil)
_ = base.SetCache(path, rawFiles, account)
}
}
files := make([]model.File, 0)

View File

@ -119,7 +119,7 @@ func (driver AliDrive) GetFile(path string, account *model.Account) (*AliFile, e
if err != nil {
return nil, err
}
parentFiles_, _ := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, dir))
parentFiles_, _ := base.GetCache(dir, account)
parentFiles, _ := parentFiles_.([]AliFile)
for _, file := range parentFiles {
if file.Name == name {

View File

@ -26,7 +26,7 @@ func (driver Alist) Items() []base.Item {
return []base.Item{
{
Name: "site_url",
Label: "site url",
Label: "alist site url",
Type: base.TypeString,
Required: true,
},

View File

@ -94,7 +94,7 @@ func (driver GoogleDrive) File(path string, account *model.Account) (*model.File
func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path)
var rawFiles []GoogleFile
cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path))
cache, err := base.GetCache(path, account)
if err == nil {
rawFiles, _ = cache.([]GoogleFile)
} else {
@ -107,7 +107,7 @@ func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.Fi
return nil, err
}
if len(rawFiles) > 0 {
_ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), rawFiles, nil)
_ = base.SetCache(path, rawFiles, account)
}
}
files := make([]model.File, 0)

View File

@ -1,7 +1,6 @@
package lanzou
import (
"fmt"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model"
@ -92,7 +91,7 @@ func (driver Lanzou) File(path string, account *model.Account) (*model.File, err
func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path)
var rawFiles []LanZouFile
cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path))
cache, err := base.GetCache(path, account)
if err == nil {
rawFiles, _ = cache.([]LanZouFile)
} else {
@ -105,7 +104,7 @@ func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, e
return nil, err
}
if len(rawFiles) > 0 {
_ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), rawFiles, nil)
_ = base.SetCache(path, rawFiles, account)
}
}
files := make([]model.File, 0)

View File

@ -154,7 +154,7 @@ func (driver Onedrive) File(path string, account *model.Account) (*model.File, e
func (driver Onedrive) Files(path string, account *model.Account) ([]model.File, error) {
path = utils.ParsePath(path)
cache, err := conf.Cache.Get(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path))
cache, err := base.GetCache(path, account)
if err == nil {
files, _ := cache.([]model.File)
return files, nil
@ -168,7 +168,7 @@ func (driver Onedrive) Files(path string, account *model.Account) ([]model.File,
files = append(files, *driver.FormatFile(&file))
}
if len(files) > 0 {
_ = conf.Cache.Set(conf.Ctx, fmt.Sprintf("%s%s", account.Name, path), files, nil)
_ = base.SetCache(path, files, account)
}
return files, nil
}