_const.py 791 B

123456789101112131415161718192021222324252627
  1. import math
  2. class LongArticlesMcpConst:
  3. """MCP 配置层:排序字段、SQL 片段、分页默认值等。"""
  4. # 分页配置
  5. DEFAULT_PAGE = 1
  6. DEFAULT_PAGE_SIZE = 20
  7. MAX_PAGE_SIZE = 100
  8. @staticmethod
  9. def normalize_pagination(page: int | None, page_size: int | None) -> tuple[int, int]:
  10. page = page or LongArticlesMcpConst.DEFAULT_PAGE
  11. page = max(page, 1)
  12. page_size = page_size or LongArticlesMcpConst.DEFAULT_PAGE_SIZE
  13. page_size = max(1, min(page_size, LongArticlesMcpConst.MAX_PAGE_SIZE))
  14. return page, page_size
  15. @staticmethod
  16. def calc_total_pages(total: int, page_size: int) -> int:
  17. if total <= 0:
  18. return 0
  19. return math.ceil(total / page_size)
  20. __all__ = ["LongArticlesMcpConst"]