mirror of https://github.com/Xhofe/alist
🎨 abstract cache method
parent
bb6e520ab5
commit
b36eaf08f0
|
@ -129,7 +129,7 @@ func (driver Pan123) GetFile(path string, account *model.Account) (*Pan123File,
|
||||||
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_, _ := base.GetCache(dir, account)
|
||||||
parentFiles, _ := parentFiles_.([]Pan123File)
|
parentFiles, _ := parentFiles_.([]Pan123File)
|
||||||
for _, file := range parentFiles {
|
for _, file := range parentFiles {
|
||||||
if file.FileName == name {
|
if file.FileName == name {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pan123 struct {}
|
type Pan123 struct{}
|
||||||
|
|
||||||
func (driver Pan123) Config() base.DriverConfig {
|
func (driver Pan123) Config() base.DriverConfig {
|
||||||
return base.DriverConfig{
|
return base.DriverConfig{
|
||||||
|
@ -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) {
|
func (driver Pan123) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
var rawFiles []Pan123File
|
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 {
|
if err == nil {
|
||||||
rawFiles, _ = cache.([]Pan123File)
|
rawFiles, _ = cache.([]Pan123File)
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,7 +109,7 @@ func (driver Pan123) Files(path string, account *model.Account) ([]model.File, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(rawFiles) > 0 {
|
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)
|
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)
|
return "", fmt.Errorf(resp.Message)
|
||||||
}
|
}
|
||||||
u,err := url.Parse(resp.Data.DownloadUrl)
|
u, err := url.Parse(resp.Data.DownloadUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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_)
|
res, err := base.NoRedirectClient.R().SetQueryParamsFromValues(u.Query()).Get(u_)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -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) {
|
func (driver Cloud189) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
var rawFiles []Cloud189File
|
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 {
|
if err == nil {
|
||||||
rawFiles, _ = cache.([]Cloud189File)
|
rawFiles, _ = cache.([]Cloud189File)
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +117,7 @@ func (driver Cloud189) Files(path string, account *model.Account) ([]model.File,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(rawFiles) > 0 {
|
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)
|
files := make([]model.File, 0)
|
||||||
|
|
|
@ -119,7 +119,7 @@ func (driver AliDrive) GetFile(path string, account *model.Account) (*AliFile, e
|
||||||
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_, _ := base.GetCache(dir, account)
|
||||||
parentFiles, _ := parentFiles_.([]AliFile)
|
parentFiles, _ := parentFiles_.([]AliFile)
|
||||||
for _, file := range parentFiles {
|
for _, file := range parentFiles {
|
||||||
if file.Name == name {
|
if file.Name == name {
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (driver Alist) Items() []base.Item {
|
||||||
return []base.Item{
|
return []base.Item{
|
||||||
{
|
{
|
||||||
Name: "site_url",
|
Name: "site_url",
|
||||||
Label: "site url",
|
Label: "alist site url",
|
||||||
Type: base.TypeString,
|
Type: base.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -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) {
|
func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
var rawFiles []GoogleFile
|
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 {
|
if err == nil {
|
||||||
rawFiles, _ = cache.([]GoogleFile)
|
rawFiles, _ = cache.([]GoogleFile)
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,7 +107,7 @@ func (driver GoogleDrive) Files(path string, account *model.Account) ([]model.Fi
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(rawFiles) > 0 {
|
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)
|
files := make([]model.File, 0)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package lanzou
|
package lanzou
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/drivers/base"
|
"github.com/Xhofe/alist/drivers/base"
|
||||||
"github.com/Xhofe/alist/model"
|
"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) {
|
func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
path = utils.ParsePath(path)
|
||||||
var rawFiles []LanZouFile
|
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 {
|
if err == nil {
|
||||||
rawFiles, _ = cache.([]LanZouFile)
|
rawFiles, _ = cache.([]LanZouFile)
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,7 +104,7 @@ func (driver Lanzou) Files(path string, account *model.Account) ([]model.File, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(rawFiles) > 0 {
|
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)
|
files := make([]model.File, 0)
|
||||||
|
|
|
@ -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) {
|
func (driver Onedrive) Files(path string, account *model.Account) ([]model.File, error) {
|
||||||
path = utils.ParsePath(path)
|
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 {
|
if err == nil {
|
||||||
files, _ := cache.([]model.File)
|
files, _ := cache.([]model.File)
|
||||||
return files, nil
|
return files, nil
|
||||||
|
@ -168,7 +168,7 @@ func (driver Onedrive) Files(path string, account *model.Account) ([]model.File,
|
||||||
files = append(files, *driver.FormatFile(&file))
|
files = append(files, *driver.FormatFile(&file))
|
||||||
}
|
}
|
||||||
if len(files) > 0 {
|
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
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue