From b36eaf08f0d6b8641fe6f07c6123acf5a2d1d781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Wed, 8 Dec 2021 22:58:44 +0800 Subject: [PATCH] :art: abstract cache method --- drivers/123/123.go | 2 +- drivers/123/driver.go | 14 +++++++------- drivers/189/driver.go | 4 ++-- drivers/alidrive/alidrive.go | 2 +- drivers/alist/driver.go | 2 +- drivers/google/driver.go | 4 ++-- drivers/lanzou/driver.go | 5 ++--- drivers/onedrive/driver.go | 4 ++-- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/drivers/123/123.go b/drivers/123/123.go index aec4ff05..3f7eda2e 100644 --- a/drivers/123/123.go +++ b/drivers/123/123.go @@ -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 { diff --git a/drivers/123/driver.go b/drivers/123/driver.go index a440bb6f..9d7e2467 100644 --- a/drivers/123/driver.go +++ b/drivers/123/driver.go @@ -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) \ No newline at end of file +var _ base.Driver = (*Pan123)(nil) diff --git a/drivers/189/driver.go b/drivers/189/driver.go index c30d5416..849f730c 100644 --- a/drivers/189/driver.go +++ b/drivers/189/driver.go @@ -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) diff --git a/drivers/alidrive/alidrive.go b/drivers/alidrive/alidrive.go index 91037f91..58a367dd 100644 --- a/drivers/alidrive/alidrive.go +++ b/drivers/alidrive/alidrive.go @@ -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 { diff --git a/drivers/alist/driver.go b/drivers/alist/driver.go index 448d1912..bc775162 100644 --- a/drivers/alist/driver.go +++ b/drivers/alist/driver.go @@ -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, }, diff --git a/drivers/google/driver.go b/drivers/google/driver.go index e0bd70c7..60ae3ae4 100644 --- a/drivers/google/driver.go +++ b/drivers/google/driver.go @@ -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) diff --git a/drivers/lanzou/driver.go b/drivers/lanzou/driver.go index 991a4079..02b00412 100644 --- a/drivers/lanzou/driver.go +++ b/drivers/lanzou/driver.go @@ -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) diff --git a/drivers/onedrive/driver.go b/drivers/onedrive/driver.go index 344762c2..ce300399 100644 --- a/drivers/onedrive/driver.go +++ b/drivers/onedrive/driver.go @@ -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 }