Skip to content

Commit 819fdbd

Browse files
authored
fix(drivers/189pc,drivers/189tv): fix extra requests when viewing files (#2791)
* fix(drivers/189pc,drivers/189tv): fix extra requests when viewing files * fix(drivers/189pc,drivers/189tv): fix extra requests when viewing files
1 parent d220b8b commit 819fdbd

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎drivers/189_tv/utils.go‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func (y *Cloud189TV) getFiles(ctx context.Context, fileId string, isFamily bool)
184184
}
185185
fullUrl += "/listFiles.action"
186186

187+
pageSize := 130 // 每一页返回的文件数量
187188
res := make([]model.Obj, 0, 130)
188189
for pageNum := 1; ; pageNum++ {
189190
var resp Cloud189FilesResp
@@ -195,7 +196,7 @@ func (y *Cloud189TV) getFiles(ctx context.Context, fileId string, isFamily bool)
195196
"mediaAttr": "0",
196197
"iconOption": "5",
197198
"pageNum": fmt.Sprint(pageNum),
198-
"pageSize": "130",
199+
"pageSize": fmt.Sprint(pageSize),
199200
})
200201
if isFamily {
201202
r.SetQueryParams(map[string]string{
@@ -218,13 +219,22 @@ func (y *Cloud189TV) getFiles(ctx context.Context, fileId string, isFamily bool)
218219
if resp.FileListAO.Count == 0 {
219220
break
220221
}
222+
223+
FolderCount := len(resp.FileListAO.FolderList) // 当前文件夹总数
224+
FileCount := len(resp.FileListAO.FileList) // 当前文件总数
225+
PageCount := FolderCount + FileCount // 当前页数总数
221226

222-
for i := 0; i < len(resp.FileListAO.FolderList); i++ {
227+
for i := 0; i < FolderCount; i++ {
223228
res = append(res, &resp.FileListAO.FolderList[i])
224229
}
225-
for i := 0; i < len(resp.FileListAO.FileList); i++ {
230+
for i := 0; i < FileCount; i++ {
226231
res = append(res, &resp.FileListAO.FileList[i])
227232
}
233+
234+
// 文件数量小于设定数量时跳出
235+
if PageCount < pageSize {
236+
break
237+
}
228238
}
229239
return res, nil
230240
}

‎drivers/189pc/utils.go‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,34 @@ func (y *Cloud189PC) put(ctx context.Context, url string, headers map[string]str
195195
}
196196

197197
func (y *Cloud189PC) getFiles(ctx context.Context, fileId string, isFamily bool) ([]model.Obj, error) {
198+
pageSize := 1000 // 每一页返回的文件数量
198199
res := make([]model.Obj, 0, 100)
199200
for pageNum := 1; ; pageNum++ {
200-
resp, err := y.getFilesWithPage(ctx, fileId, isFamily, pageNum, 1000, y.OrderBy, y.OrderDirection)
201+
resp, err := y.getFilesWithPage(ctx, fileId, isFamily, pageNum, pageSize, y.OrderBy, y.OrderDirection)
201202
if err != nil {
202203
return nil, err
203204
}
204205
// 获取完毕跳出
205206
if resp.FileListAO.Count == 0 {
206207
break
207208
}
209+
210+
FolderCount := len(resp.FileListAO.FolderList) // 当前文件夹总数
211+
FileCount := len(resp.FileListAO.FileList) // 当前文件总数
212+
PageCount := FolderCount + FileCount // 当前页数总数
208213

209-
for i := 0; i < len(resp.FileListAO.FolderList); i++ {
214+
for i := 0; i < FolderCount; i++ {
210215
res = append(res, &resp.FileListAO.FolderList[i])
211216
}
212-
for i := 0; i < len(resp.FileListAO.FileList); i++ {
217+
for i := 0; i < FileCount; i++ {
213218
resp.FileListAO.FileList[i].ParentID = fileId
214219
res = append(res, &resp.FileListAO.FileList[i])
215220
}
221+
222+
// 当前文件数量小于设定数量则跳出
223+
if PageCount < pageSize {
224+
break
225+
}
216226
}
217227
return res, nil
218228
}

0 commit comments

Comments
 (0)