fix(123): adapt new file list api (close #3464)

pull/3471/head
Andy Hsu 2023-02-16 22:09:33 +08:00
parent 6ee4c10e8f
commit 236c17176c
1 changed files with 9 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"strconv"
"github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
@ -77,18 +78,19 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r
} }
func (d *Pan123) getFiles(parentId string) ([]File, error) { func (d *Pan123) getFiles(parentId string) ([]File, error) {
next := "0" page := 1
res := make([]File, 0) res := make([]File, 0)
for next != "-1" { for {
var resp Files var resp Files
query := map[string]string{ query := map[string]string{
"driveId": "0", "driveId": "0",
"limit": "100", "limit": "100",
"next": next, "next": "0",
"orderBy": d.OrderBy, "orderBy": d.OrderBy,
"orderDirection": d.OrderDirection, "orderDirection": d.OrderDirection,
"parentFileId": parentId, "parentFileId": parentId,
"trashed": "false", "trashed": "false",
"Page": strconv.Itoa(page),
} }
_, err := d.request("https://www.123pan.com/api/file/list/new", http.MethodGet, func(req *resty.Request) { _, err := d.request("https://www.123pan.com/api/file/list/new", http.MethodGet, func(req *resty.Request) {
req.SetQueryParams(query) req.SetQueryParams(query)
@ -96,8 +98,11 @@ func (d *Pan123) getFiles(parentId string) ([]File, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
next = resp.Data.Next page++
res = append(res, resp.Data.InfoList...) res = append(res, resp.Data.InfoList...)
if len(resp.Data.InfoList) == 0 || resp.Data.Next == "-1" {
break
}
} }
return res, nil return res, nil
} }