import { getSessionAccount } from "@/lib/auth/require-session"; import { canReadPage } from "@/lib/auth/permissions"; import { parseMatchIdParam, readMatchLogFile, } from "@/lib/match-logs-server"; export async function GET( _request: Request, context: { params: Promise<{ matchId: string }> }, ) { const account = await getSessionAccount(); if ( !account || (!canReadPage(account, "matches") && !canReadPage(account, "analysis")) ) { return Response.json({ error: "Unauthorized" }, { status: 401 }); } const { matchId: raw } = await context.params; const matchId = parseMatchIdParam(raw); if (matchId == null) { return Response.json({ error: "Invalid match id" }, { status: 400 }); } const result = await readMatchLogFile(matchId); if (!result.ok) { return Response.json({ error: result.message }, { status: result.status }); } return Response.json({ matchId, content: result.content }); }