import { withUser, json, ApiError } from "@/lib/api"; import { getArenaScoreboard } from "@/lib/arena/service"; import { CRITERION_RE, isTaskCategory } from "@/lib/arena/scoring"; export const dynamic = "force-dynamic"; /** * GET /api/arena/scoreboard?category=coding|research|writing|reasoning|general&criterion=best|value|… * → { rows: ScoreboardRow[], sessions, votes } */ export const GET = withUser(async ({ req, user }) => { const url = new URL(req.url); const category = url.searchParams.get("category") || null; const criterion = url.searchParams.get("criterion") || null; if (category && !isTaskCategory(category)) throw new ApiError(400, "Unknown category", "VALIDATION_ERROR"); if (criterion && !CRITERION_RE.test(criterion)) throw new ApiError(400, "Unknown criterion", "VALIDATION_ERROR"); return json(await getArenaScoreboard(user.id, { category: category && isTaskCategory(category) ? category : null, criterion })); });