mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-02 05:47:31 +08:00
Refactor: consolidate page and page_size (#17597)
This commit is contained in:
@@ -14,11 +14,30 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
DEFAULT_PAGE = 1
|
||||
DEFAULT_PAGE_SIZE = 30
|
||||
REST_API_MAX_PAGE_SIZE = 100
|
||||
|
||||
|
||||
def validate_rest_api_page_size(page_size: int) -> int:
|
||||
"""Validate REST API page_size values against the public maximum."""
|
||||
if page_size > REST_API_MAX_PAGE_SIZE:
|
||||
def validate_rest_api_page(page) -> int:
|
||||
"""Validate page, if invalid, silent fallback to default page"""
|
||||
try:
|
||||
int_page = int(page)
|
||||
except (TypeError, ValueError):
|
||||
return DEFAULT_PAGE
|
||||
if int_page < 1:
|
||||
return DEFAULT_PAGE
|
||||
return int_page
|
||||
|
||||
|
||||
def validate_rest_api_page_size(page_size) -> int:
|
||||
"""Validate page_size, if invalid, silent fallback to default page_size, and validate it against the public maximum."""
|
||||
try:
|
||||
int_page_size = int(page_size)
|
||||
except (TypeError, ValueError):
|
||||
return DEFAULT_PAGE_SIZE
|
||||
if int_page_size < 1:
|
||||
return DEFAULT_PAGE_SIZE
|
||||
if int_page_size > REST_API_MAX_PAGE_SIZE:
|
||||
raise ValueError(f"page_size must be less than or equal to {REST_API_MAX_PAGE_SIZE}")
|
||||
return page_size
|
||||
return int_page_size
|
||||
|
||||
Reference in New Issue
Block a user