| 123456789101112131415161718192021222324252627 |
- import math
- class LongArticlesMcpConst:
- """MCP 配置层:排序字段、SQL 片段、分页默认值等。"""
- # 分页配置
- DEFAULT_PAGE = 1
- DEFAULT_PAGE_SIZE = 20
- MAX_PAGE_SIZE = 100
- @staticmethod
- def normalize_pagination(page: int | None, page_size: int | None) -> tuple[int, int]:
- page = page or LongArticlesMcpConst.DEFAULT_PAGE
- page = max(page, 1)
- page_size = page_size or LongArticlesMcpConst.DEFAULT_PAGE_SIZE
- page_size = max(1, min(page_size, LongArticlesMcpConst.MAX_PAGE_SIZE))
- return page, page_size
- @staticmethod
- def calc_total_pages(total: int, page_size: int) -> int:
- if total <= 0:
- return 0
- return math.ceil(total / page_size)
- __all__ = ["LongArticlesMcpConst"]
|