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.
pull/6859/head
seiuneko 2024-07-20 12:27:18 +08:00 committed by GitHub
parent 2b74999703
commit 2d57529e77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -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) { 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -87,8 +87,9 @@ var _ model.Thumb = (*File)(nil)
type Files struct { type Files struct {
//BaseResp //BaseResp
Data struct { Data struct {
InfoList []File `json:"InfoList"`
Next string `json:"Next"` Next string `json:"Next"`
Total int `json:"Total"`
InfoList []File `json:"InfoList"`
} `json:"data"` } `json:"data"`
} }

View File

@ -3,6 +3,7 @@ package _123
import ( import (
"errors" "errors"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"hash/crc32" "hash/crc32"
"math" "math"
"math/rand" "math/rand"
@ -232,8 +233,9 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r
return body, nil return body, nil
} }
func (d *Pan123) getFiles(parentId string) ([]File, error) { func (d *Pan123) getFiles(parentId string, name string) ([]File, error) {
page := 1 page := 1
total := 0
res := make([]File, 0) res := make([]File, 0)
// 2024-02-06 fix concurrency by 123pan // 2024-02-06 fix concurrency by 123pan
for { for {
@ -265,9 +267,13 @@ func (d *Pan123) getFiles(parentId string) ([]File, error) {
} }
page++ page++
res = append(res, resp.Data.InfoList...) res = append(res, resp.Data.InfoList...)
total = resp.Data.Total
if len(resp.Data.InfoList) == 0 || resp.Data.Next == "-1" { if len(resp.Data.InfoList) == 0 || resp.Data.Next == "-1" {
break 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 return res, nil
} }