_const.py 806 B

123456789101112131415161718192021222324252627282930
  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(
  10. page: int | None, page_size: int | None
  11. ) -> tuple[int, int]:
  12. page = page or LongArticlesMcpConst.DEFAULT_PAGE
  13. page = max(page, 1)
  14. page_size = page_size or LongArticlesMcpConst.DEFAULT_PAGE_SIZE
  15. page_size = max(1, min(page_size, LongArticlesMcpConst.MAX_PAGE_SIZE))
  16. return page, page_size
  17. @staticmethod
  18. def calc_total_pages(total: int, page_size: int) -> int:
  19. if total <= 0:
  20. return 0
  21. return math.ceil(total / page_size)
  22. __all__ = ["LongArticlesMcpConst"]