Skip to content

Commit 0fa863e

Browse files
authored
fix: support all pagination mode (#9512)
1 parent d509a87 commit 0fa863e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

server/handles/fsread.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type ObjLabelResp struct {
8282
const (
8383
DefaultPerPage = 200
8484
MaxPerPage = 500
85+
AllPerPage = -1
8586
)
8687

8788
func FsList(c *gin.Context) {
@@ -136,7 +137,7 @@ func FsList(c *gin.Context) {
136137
total, pageObjs := pagination(filtered, &req.PageReq)
137138
respContent := toObjsResp(pageObjs, reqPath, isEncrypt(meta, reqPath))
138139
pagesTotal := calcPagesTotal(total, req.PerPage)
139-
hasMore := req.Page*req.PerPage < total
140+
hasMore := req.PerPage != AllPerPage && req.Page*req.PerPage < total
140141

141142
common.SuccessResp(c, FsListResp{
142143
Content: respContent,
@@ -253,7 +254,10 @@ func normalizeListPage(page, perPage int) (int, int) {
253254
effPage = 1
254255
}
255256
effPerPage := perPage
256-
if effPerPage <= 0 {
257+
if effPerPage < 0 {
258+
return effPage, AllPerPage
259+
}
260+
if effPerPage == 0 {
257261
effPerPage = DefaultPerPage
258262
}
259263
if effPerPage > MaxPerPage {
@@ -263,6 +267,12 @@ func normalizeListPage(page, perPage int) (int, int) {
263267
}
264268

265269
func calcPagesTotal(total, perPage int) int {
270+
if perPage == AllPerPage {
271+
if total > 0 {
272+
return 1
273+
}
274+
return 0
275+
}
266276
if total <= 0 || perPage <= 0 {
267277
return 0
268278
}
@@ -272,6 +282,9 @@ func calcPagesTotal(total, perPage int) int {
272282
func pagination(objs []model.Obj, req *model.PageReq) (int, []model.Obj) {
273283
pageIndex, pageSize := req.Page, req.PerPage
274284
total := len(objs)
285+
if pageSize == AllPerPage {
286+
return total, objs
287+
}
275288
start := (pageIndex - 1) * pageSize
276289
if start > total {
277290
return total, []model.Obj{}

server/handles/share_public.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func ListPublicShare(c *gin.Context) {
147147
Total: int64(total),
148148
Page: req.Page,
149149
PerPage: req.PerPage,
150-
HasMore: req.Page*req.PerPage < total,
150+
HasMore: req.PerPage != AllPerPage && req.Page*req.PerPage < total,
151151
PagesTotal: calcPagesTotal(total, req.PerPage),
152152
})
153153
}

0 commit comments

Comments
 (0)