init
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { ADMIN_SESSION_COOKIE } from "@/lib/auth/session";
|
||||
import { parseMatchmakerLogParam } from "@/lib/matchmaker-log-source";
|
||||
import { readMatchmakerLogFile } from "@/lib/matchmaker-logs-server";
|
||||
|
||||
const NO_STORE = { "Cache-Control": "no-store, max-age=0" };
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const cookieStore = await cookies();
|
||||
if (cookieStore.get(ADMIN_SESSION_COOKIE)?.value !== "1") {
|
||||
return Response.json(
|
||||
{ error: "Unauthorized" },
|
||||
{ status: 401, headers: NO_STORE },
|
||||
);
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const source = parseMatchmakerLogParam(searchParams.get("mklog"));
|
||||
|
||||
const result = await readMatchmakerLogFile(source);
|
||||
if (!result.ok) {
|
||||
return Response.json(
|
||||
{ error: result.message },
|
||||
{ status: result.status, headers: NO_STORE },
|
||||
);
|
||||
}
|
||||
|
||||
return Response.json(
|
||||
{ content: result.content },
|
||||
{ headers: NO_STORE },
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user