init
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { ADMIN_SESSION_COOKIE } from "@/lib/auth/session";
|
||||
import {
|
||||
parseMatchIdParam,
|
||||
readMatchLogFile,
|
||||
} from "@/lib/match-logs-server";
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
context: { params: Promise<{ matchId: string }> },
|
||||
) {
|
||||
const cookieStore = await cookies();
|
||||
if (cookieStore.get(ADMIN_SESSION_COOKIE)?.value !== "1") {
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user