Pause
This commit is contained in:
19
server.ts
19
server.ts
@@ -26,6 +26,7 @@ const gameState: GameState = {
|
||||
active: null,
|
||||
scores: Object.fromEntries(MODELS.map((m) => [m.name, 0])),
|
||||
done: false,
|
||||
isPaused: false,
|
||||
};
|
||||
|
||||
// ── WebSocket clients ───────────────────────────────────────────────────────
|
||||
@@ -56,6 +57,24 @@ const server = Bun.serve({
|
||||
const file = Bun.file(path);
|
||||
return new Response(file);
|
||||
}
|
||||
if (url.pathname === "/api/pause") {
|
||||
const secret = url.searchParams.get("secret");
|
||||
if (process.env.ADMIN_SECRET && secret === process.env.ADMIN_SECRET) {
|
||||
gameState.isPaused = true;
|
||||
broadcast();
|
||||
return new Response("Paused", { status: 200 });
|
||||
}
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
if (url.pathname === "/api/resume") {
|
||||
const secret = url.searchParams.get("secret");
|
||||
if (process.env.ADMIN_SECRET && secret === process.env.ADMIN_SECRET) {
|
||||
gameState.isPaused = false;
|
||||
broadcast();
|
||||
return new Response("Resumed", { status: 200 });
|
||||
}
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
if (url.pathname === "/api/history") {
|
||||
const page = parseInt(url.searchParams.get("page") || "1", 10);
|
||||
return new Response(JSON.stringify(getRounds(page)), {
|
||||
|
||||
Reference in New Issue
Block a user