mirror of https://github.com/Xhofe/alist
fix(aliyundrive_open): `openFile/list` rate limit
parent
f646d2a699
commit
ca5a53fc24
|
@ -22,7 +22,7 @@ type AliyundriveOpen struct {
|
||||||
|
|
||||||
DriveId string
|
DriveId string
|
||||||
|
|
||||||
limitList func(ctx context.Context, dir model.Obj) ([]model.Obj, error)
|
limitList func(ctx context.Context, data base.Json) (*Files, error)
|
||||||
limitLink func(ctx context.Context, file model.Obj) (*model.Link, error)
|
limitLink func(ctx context.Context, file model.Obj) (*model.Link, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ func (d *AliyundriveOpen) Drop(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *AliyundriveOpen) list(ctx context.Context, dir model.Obj) ([]model.Obj, error) {
|
func (d *AliyundriveOpen) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
||||||
files, err := d.getFiles(dir.GetID())
|
files, err := d.getFiles(ctx, dir.GetID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,6 @@ func (d *AliyundriveOpen) list(ctx context.Context, dir model.Obj) ([]model.Obj,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *AliyundriveOpen) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
|
||||||
return d.limitList(ctx, dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *AliyundriveOpen) link(ctx context.Context, file model.Obj) (*model.Link, error) {
|
func (d *AliyundriveOpen) link(ctx context.Context, file model.Obj) (*model.Link, error) {
|
||||||
res, err := d.request("/adrive/v1.0/openFile/getDownloadUrl", http.MethodPost, func(req *resty.Request) {
|
res, err := d.request("/adrive/v1.0/openFile/getDownloadUrl", http.MethodPost, func(req *resty.Request) {
|
||||||
req.SetBody(base.Json{
|
req.SetBody(base.Json{
|
||||||
|
|
|
@ -77,14 +77,24 @@ func (d *AliyundriveOpen) request(uri, method string, callback base.ReqCallback,
|
||||||
return res.Body(), nil
|
return res.Body(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *AliyundriveOpen) getFiles(fileId string) ([]File, error) {
|
func (d *AliyundriveOpen) list(ctx context.Context, data base.Json) (*Files, error) {
|
||||||
|
var resp Files
|
||||||
|
_, err := d.request("/adrive/v1.0/openFile/list", http.MethodPost, func(req *resty.Request) {
|
||||||
|
req.SetBody(data).SetResult(&resp)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *AliyundriveOpen) getFiles(ctx context.Context, fileId string) ([]File, error) {
|
||||||
marker := "first"
|
marker := "first"
|
||||||
res := make([]File, 0)
|
res := make([]File, 0)
|
||||||
for marker != "" {
|
for marker != "" {
|
||||||
if marker == "first" {
|
if marker == "first" {
|
||||||
marker = ""
|
marker = ""
|
||||||
}
|
}
|
||||||
var resp Files
|
|
||||||
data := base.Json{
|
data := base.Json{
|
||||||
"drive_id": d.DriveId,
|
"drive_id": d.DriveId,
|
||||||
"limit": 200,
|
"limit": 200,
|
||||||
|
@ -98,9 +108,7 @@ func (d *AliyundriveOpen) getFiles(fileId string) ([]File, error) {
|
||||||
//"video_thumbnail_width": 480,
|
//"video_thumbnail_width": 480,
|
||||||
//"image_thumbnail_width": 480,
|
//"image_thumbnail_width": 480,
|
||||||
}
|
}
|
||||||
_, err := d.request("/adrive/v1.0/openFile/list", http.MethodPost, func(req *resty.Request) {
|
resp, err := d.limitList(ctx, data)
|
||||||
req.SetBody(data).SetResult(&resp)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue