Skip to content

Commit 6faecbd

Browse files
committed
feat: add cache for xunlei
1 parent 34ed05c commit 6faecbd

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/xunlei/driver.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,19 @@ func (driver XunLeiCloud) File(path string, account *model.Account) (*model.File
8989
}
9090

9191
func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.File, error) {
92+
cache, err := base.GetCache(path, account)
93+
if err == nil {
94+
files, _ := cache.([]model.File)
95+
return files, nil
96+
}
9297
file, err := driver.File(utils.ParsePath(path), account)
9398
if err != nil {
9499
return nil, err
95100
}
96101

97102
var fileList FileList
98-
url := fmt.Sprintf("https://api-pan.xunlei.com/drive/v1/files?parent_id=%s&page_token=%s&with_audit=true&filters=%s", file.Id, "", url.QueryEscape(`{"phase": {"eq": "PHASE_TYPE_COMPLETE"}, "trashed":{"eq":false}}`))
99-
if err = GetState(account).Request("GET", url, nil, &fileList, account); err != nil {
103+
u := fmt.Sprintf("https://api-pan.xunlei.com/drive/v1/files?parent_id=%s&page_token=%s&with_audit=true&filters=%s", file.Id, "", url.QueryEscape(`{"phase": {"eq": "PHASE_TYPE_COMPLETE"}, "trashed":{"eq":false}}`))
104+
if err = GetState(account).Request("GET", u, nil, &fileList, account); err != nil {
100105
return nil, err
101106
}
102107

@@ -106,6 +111,9 @@ func (driver XunLeiCloud) Files(path string, account *model.Account) ([]model.Fi
106111
files = append(files, *driver.formatFile(&file))
107112
}
108113
}
114+
if len(files) > 0 {
115+
_ = base.SetCache(path, files, account)
116+
}
109117
return files, nil
110118
}
111119

@@ -134,15 +142,15 @@ func (driver XunLeiCloud) Link(args base.Args, account *model.Account) (*base.Li
134142
if file.Type == conf.FOLDER {
135143
return nil, base.ErrNotFile
136144
}
137-
var lfile Files
138-
if err = GetState(account).Request("GET", fmt.Sprintf("https://api-pan.xunlei.com/drive/v1/files/%s?&with_audit=true", file.Id), nil, &lfile, account); err != nil {
145+
var lFile Files
146+
if err = GetState(account).Request("GET", fmt.Sprintf("https://api-pan.xunlei.com/drive/v1/files/%s?&with_audit=true", file.Id), nil, &lFile, account); err != nil {
139147
return nil, err
140148
}
141149
return &base.Link{
142150
Headers: []base.Header{
143151
{Name: "User-Agent", Value: base.UserAgent},
144152
},
145-
Url: lfile.WebContentLink,
153+
Url: lFile.WebContentLink,
146154
}, nil
147155
}
148156

0 commit comments

Comments
 (0)