diff --git a/src/app/api/doubts/route.ts b/src/app/api/doubts/route.ts index 061c5456..710481a5 100644 --- a/src/app/api/doubts/route.ts +++ b/src/app/api/doubts/route.ts @@ -136,7 +136,7 @@ export async function GET(req: Request) { const pageStr = searchParams.get("page"); const offsetStr = searchParams.get("offset"); const limitStr = searchParams.get("limit"); - const limit = parsePositiveInt(limitStr, 20); + const limit = parsePositiveInt(limitStr, 20, 100); const offset = offsetStr ? parsePositiveInt(offsetStr, 0) : pageStr diff --git a/src/lib/utils/utils.ts b/src/lib/utils/utils.ts index 0e8fc071..b10598fe 100644 --- a/src/lib/utils/utils.ts +++ b/src/lib/utils/utils.ts @@ -7,7 +7,8 @@ export function cn(...inputs: ClassValue[]) { export const parsePositiveInt = ( value: string | null, - fallback: number + fallback: number, + max?: number ): number => { if (!value || !/^\d+$/.test(value.trim())) { return fallback; @@ -19,5 +20,9 @@ export const parsePositiveInt = ( return fallback; } + if (max !== undefined && parsed > max) { + return max; + } + return parsed; };