v3: code quality pass, various bug fixes

This commit is contained in:
khannurien
2026-03-23 07:47:49 +00:00
parent d94a319d96
commit fbbbb43258
44 changed files with 1060 additions and 698 deletions

22
api/lib/pagination.ts Normal file
View File

@@ -0,0 +1,22 @@
/**
* Parses page/limit query parameters with sensible defaults and bounds.
* page: clamped to [1, ∞)
* limit: clamped to [1, 100], defaults to 20
*/
export function parsePagination(
params: URLSearchParams,
defaultLimit = 20,
): { page: number; limit: number } {
const page = Math.max(
1,
parseInt(params.get("page") ?? "1") || 1,
);
const limit = Math.min(
Math.max(
1,
parseInt(params.get("limit") ?? String(defaultLimit)) || defaultLimit,
),
100,
);
return { page, limit };
}