Let owners/operators mute or unmute new public/private sends from a human seat while retaining history, incoming messages, gameplay and credentials. Fence metadata and durable audit writes with live authority, membership and versions. Preserve exact admin/message retries and inherit restrictions through seat recovery. Validation: types/lint, 5431 offline tests, build, 52 HTTP integration tests, 24 administrator HTTP groups, independent SQL/privacy/UI review and desktop/mobile refresh acceptance. All 2230 prior games and 4746 seats preserved. Additive migration 0016. Verified runtime fingerprint 588967fbb9c2e3b6abe2990c4fce96ee69e2256fb7e3ee416314b87593cebba9; documentation-only grammar/button-label review gives b5e57bdd26812debede91c588e38f247f1fa895ad23e7ae30bc8550eedcd90ec. New-revision deployed acceptance remains open; full admin/rules scope is unfinished.
30 lines
1.7 KiB
TypeScript
30 lines
1.7 KiB
TypeScript
import { env } from 'cloudflare:workers';
|
|
import { AdminError, requireAdmin } from '@/db/admin-access';
|
|
import { applyAdminDiscussion, readAdminDiscussion } from '@/db/admin-discussion';
|
|
import { validAdminDiscussionInput } from '@/lib/admin-discussion';
|
|
import { adminBody, adminFailure, adminResponse, adminToken } from '@/lib/admin-http';
|
|
|
|
function code(request: Request) {
|
|
const code = new URL(request.url).pathname.split('/').at(-2)?.toUpperCase() ?? '';
|
|
if (code.length !== 8 || !/^[A-Z2-9]{8}$/.test(code)) throw new AdminError('Enter the eight-character room code.', 400);
|
|
return code;
|
|
}
|
|
export async function GET(request: Request) {
|
|
try {
|
|
const identity = await requireAdmin(env.DB, adminToken(request));
|
|
if (request.headers.has('X-Dune-Admin-Id') && request.headers.get('X-Dune-Admin-Id') !== identity.id)
|
|
throw new AdminError('The signed-in administrator changed. Reload administration before continuing.', 401);
|
|
return adminResponse(await readAdminDiscussion(env.DB, identity, code(request)));
|
|
} catch (error) { return adminFailure(error); }
|
|
}
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const input = await adminBody(request, env.DUNE_PUBLIC_ORIGIN);
|
|
const identity = await requireAdmin(env.DB, adminToken(request), ['owner','operator']);
|
|
if (request.headers.get('X-Dune-Admin-Id') !== identity.id)
|
|
throw new AdminError('The signed-in administrator changed. Reload administration before continuing.', 401);
|
|
if (!validAdminDiscussionInput(input)) throw new AdminError('Choose a participant, discussion setting, current versions and a short reason.', 400);
|
|
return adminResponse(await applyAdminDiscussion(env.DB, identity, code(request), input));
|
|
} catch (error) { return adminFailure(error); }
|
|
}
|