Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/api/doubts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,5 +20,9 @@ export const parsePositiveInt = (
return fallback;
}

if (max !== undefined && parsed > max) {
return max;
}

return parsed;
};
Loading