Skip to content

Commit fdedd64

Browse files
committed
feat: Use paging in ListChildren
1 parent 1bad007 commit fdedd64

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

link_folder.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package proton
33
import (
44
"context"
55
"fmt"
6+
"strconv"
67

78
"github.com/bradenaw/juniper/xslices"
89
"github.com/go-resty/resty/v2"
@@ -13,13 +14,29 @@ func (c *Client) ListChildren(ctx context.Context, shareID, linkID string) ([]Li
1314
Links []Link
1415
}
1516

16-
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
17-
return r.SetResult(&res).Get("/drive/shares/" + shareID + "/folders/" + linkID + "/children")
18-
}); err != nil {
19-
return nil, err
17+
var links []Link
18+
19+
for page := 0; ; page++ {
20+
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
21+
return r.
22+
SetQueryParams(map[string]string{
23+
"Page": strconv.Itoa(page),
24+
"PageSize": strconv.Itoa(maxPageSize),
25+
}).
26+
SetResult(&res).
27+
Get("/drive/shares/" + shareID + "/folders/" + linkID + "/children")
28+
}); err != nil {
29+
return nil, err
30+
}
31+
32+
if len(res.Links) == 0 {
33+
break
34+
}
35+
36+
links = append(links, res.Links...)
2037
}
2138

22-
return res.Links, nil
39+
return links, nil
2340
}
2441

2542
func (c *Client) TrashChildren(ctx context.Context, shareID, linkID string, childIDs ...string) error {
@@ -34,7 +51,7 @@ func (c *Client) TrashChildren(ctx context.Context, shareID, linkID string, chil
3451
}
3552
}
3653

37-
for _, childIDs := range xslices.Chunk(childIDs, 150) {
54+
for _, childIDs := range xslices.Chunk(childIDs, maxPageSize) {
3855
req := struct {
3956
LinkIDs []string
4057
}{
@@ -69,7 +86,7 @@ func (c *Client) DeleteChildren(ctx context.Context, shareID, linkID string, chi
6986
}
7087
}
7188

72-
for _, childIDs := range xslices.Chunk(childIDs, 150) {
89+
for _, childIDs := range xslices.Chunk(childIDs, maxPageSize) {
7390
req := struct {
7491
LinkIDs []string
7592
}{

0 commit comments

Comments
 (0)