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
8 changes: 8 additions & 0 deletions web/__tests__/api/skills-get-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ describe("GET /api/skills cache headers", () => {
expect(res.headers.get("Cache-Control")).toContain("s-maxage=60");
});

it("defaults an invalid page query to the first page", async () => {
const res = await GET(makeRequest("?page=not-a-number&mode=fast"));
const body = await res.json();

expect(res.status).toBe(200);
expect(body.pagination).toMatchObject({ page: 1, pageSize: 20 });
});

it("keeps shared caching when buyer status is not requested", async () => {
const res = await GET(
makeRequest("?sort=newest&page=1&buyer=11111111111111111111111111111111")
Expand Down
8 changes: 7 additions & 1 deletion web/app/api/skills/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ const MAX_PAGE_SIZE = 50;
const rpc = createSolanaRpc(DEFAULT_SOLANA_RPC_URL);
const configuredSolanaChainContext = getConfiguredSolanaChainContext();

function parsePage(value: string | null): number {
if (!value) return 1;
const parsed = Number.parseInt(value, 10);
return Number.isFinite(parsed) ? Math.max(1, parsed) : 1;
}

function parsePageSize(value: string | null): number {
if (!value) return DEFAULT_PAGE_SIZE;
const parsed = Number.parseInt(value, 10);
Expand Down Expand Up @@ -663,7 +669,7 @@ export async function GET(request: NextRequest) {
searchParams.get("buyerStatus") === "1" ||
searchParams.get("includeBuyerStatus") === "true";
const tags = searchParams.get("tags");
const page = Math.max(1, parseInt(searchParams.get("page") || "1"));
const page = parsePage(searchParams.get("page"));
const pageSize = parsePageSize(
searchParams.get("pageSize") ?? searchParams.get("limit")
);
Expand Down
Loading