From 2d57529e7728aa2512c8663c226217e7b97cea83 Mon Sep 17 00:00:00 2001 From: seiuneko <25706824+seiuneko@users.noreply.github.com> Date: Sat, 20 Jul 2024 12:27:18 +0800 Subject: [PATCH] fix(123pan): add warning for mismatched file count when listing files (#6814) Fixes an issue where using `file_name` order could result in incorrect file counts compared to response fields. --- drivers/123/driver.go | 2 +- drivers/123/types.go | 3 ++- drivers/123/util.go | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/123/driver.go b/drivers/123/driver.go index 240027405d5..bd7089e85d2 100644 --- a/drivers/123/driver.go +++ b/drivers/123/driver.go @@ -53,7 +53,7 @@ func (d *Pan123) Drop(ctx context.Context) error { } func (d *Pan123) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) { - files, err := d.getFiles(dir.GetID()) + files, err := d.getFiles(dir.GetID(), dir.GetName()) if err != nil { return nil, err } diff --git a/drivers/123/types.go b/drivers/123/types.go index b79be12e201..a8682c52fc9 100644 --- a/drivers/123/types.go +++ b/drivers/123/types.go @@ -87,8 +87,9 @@ var _ model.Thumb = (*File)(nil) type Files struct { //BaseResp Data struct { - InfoList []File `json:"InfoList"` Next string `json:"Next"` + Total int `json:"Total"` + InfoList []File `json:"InfoList"` } `json:"data"` } diff --git a/drivers/123/util.go b/drivers/123/util.go index 9d5d6780167..86816df21d7 100644 --- a/drivers/123/util.go +++ b/drivers/123/util.go @@ -3,6 +3,7 @@ package _123 import ( "errors" "fmt" + log "github.com/sirupsen/logrus" "hash/crc32" "math" "math/rand" @@ -232,8 +233,9 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r return body, nil } -func (d *Pan123) getFiles(parentId string) ([]File, error) { +func (d *Pan123) getFiles(parentId string, name string) ([]File, error) { page := 1 + total := 0 res := make([]File, 0) // 2024-02-06 fix concurrency by 123pan for { @@ -265,9 +267,13 @@ func (d *Pan123) getFiles(parentId string) ([]File, error) { } page++ res = append(res, resp.Data.InfoList...) + total = resp.Data.Total if len(resp.Data.InfoList) == 0 || resp.Data.Next == "-1" { break } } + if len(res) != total { + log.Warnf("incorrect file count from remote at %s: expected %d, got %d", name, total, len(res)) + } return res, nil }