Skip to content

Commit

Permalink
fix(123pan): add warning for mismatched file count when listing files (
Browse files Browse the repository at this point in the history
…#6814)

Fixes an issue where using `file_name` order could result in incorrect file counts compared to response fields.
  • Loading branch information
seiuneko authored Jul 20, 2024
1 parent 2b74999 commit 2d57529
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion drivers/123/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion drivers/123/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
8 changes: 7 additions & 1 deletion drivers/123/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package _123
import (
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"hash/crc32"
"math"
"math/rand"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 2d57529

Please sign in to comment.