mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-12 02:20:28 +08:00
feat: implement cursor-based pagination across various components and APIs
This commit is contained in:
@@ -9,7 +9,25 @@ def success(data: Any = None, msg: str = "ok", code: int = 0):
|
||||
def page(items: list[Any], total: int, page: int, page_size: int):
|
||||
"""统一分页数据结构。"""
|
||||
pages = (total + page_size - 1) // page_size if page_size else 0
|
||||
return {"items": items, "total": total, "page": page, "page_size": page_size, "pages": pages}
|
||||
return {"items": items, "total": total, "page": page, "page_size": page_size, "pages": pages, "pagination_mode": "paged"}
|
||||
|
||||
|
||||
def cursor_page(
|
||||
items: list[Any],
|
||||
page_size: int,
|
||||
*,
|
||||
cursor: str | None = None,
|
||||
next_cursor: str | None = None,
|
||||
):
|
||||
"""无总数游标分页结构。"""
|
||||
return {
|
||||
"items": items,
|
||||
"page_size": page_size,
|
||||
"pagination_mode": "cursor",
|
||||
"cursor": cursor,
|
||||
"next_cursor": next_cursor,
|
||||
"has_next": bool(next_cursor),
|
||||
}
|
||||
|
||||
|
||||
def error(msg: str, code: int = 1, data: Optional[Any] = None):
|
||||
|
||||
Reference in New Issue
Block a user