Skip to content

Commit 6eec17f

Browse files
authored
Revise object storage list pagination after API response change (#275)
List Objects API now returns `{ items, hasNext, nextCursor }` instead of a bare array. Use `hasNext` and `nextCursor` for pagination.
1 parent 2fb2d16 commit 6eec17f

4 files changed

Lines changed: 39 additions & 18 deletions

File tree

pkg/client/blueprints/blueprints_gen.go

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/client_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/storage/storage_gen.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/storage/repo.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,23 @@ func (r *Repo) List(ctx context.Context, ownerId, region, cursor string, limit i
111111
return nil, "", nil
112112
}
113113

114-
respOK := *resp.JSON200
115-
objects := make([]ObjectInfo, len(respOK))
116-
var lastCursor string
117-
for i, bwc := range respOK {
114+
respOK := resp.JSON200
115+
items := respOK.Items
116+
objects := make([]ObjectInfo, len(items))
117+
for i, bwc := range items {
118118
objects[i] = ObjectInfo{
119119
Key: bwc.Object.Key,
120120
SizeBytes: bwc.Object.SizeBytes,
121121
LastModified: bwc.Object.LastModified,
122122
}
123-
lastCursor = bwc.Cursor
124123
}
125124

126-
// Return cursor only if we got a full page (more data likely exists)
127-
if len(objects) < limit {
128-
lastCursor = ""
125+
var nextCursor string
126+
if respOK.HasNext && respOK.NextCursor != nil {
127+
nextCursor = *respOK.NextCursor
129128
}
130129

131-
return objects, lastCursor, nil
130+
return objects, nextCursor, nil
132131
}
133132

134133
// UploadToPresignedURL uploads file content to a presigned URL

0 commit comments

Comments
 (0)