Add owner-only room backup snapshots and audited exports

This commit is contained in:
Quintine committed 2026-09-28 20:12:57 +10:00
1 parent 92564f8de5
commit 53a1ba77a1
19 files changed
+5613 -4

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
'use client';
import { useEffect, useState } from 'react';
import { AdminBackups } from '@/components/admin-backups';
import { Button } from '@/components/ui/button';
import { ClientRequestError, requestJson } from '@/lib/client-request';
import '../admin.css';
type Account = { id: string; role: 'owner' | 'operator' | 'viewer' };
const errorMessage = (error: unknown) => error instanceof Error ? error.message : 'Administrator access could not be checked.';
export default function BackupsPage() {
const [owner, setOwner] = useState<Account | null>(null);
const [loading, setLoading] = useState(true);
const [notice, setNotice] = useState('');
const [revision, setRevision] = useState(0);
useEffect(() => {
let canceled = false;
requestJson<{ admin: Account }>('/api/admin/session', { cache: 'no-store' })
.then(result => {
if (canceled) return;
if (result.admin?.role !== 'owner' || !result.admin.id) {
setOwner(null);
setNotice('Room backups are available only to an owner. Sign in with an owner account to continue.');
} else { setOwner(result.admin); setNotice(''); }
})
.catch(error => { if (!canceled) {
setOwner(null);
setNotice(error instanceof ClientRequestError && error.status === 401
? 'Administrator sign-in required. Sign in to administration with an owner account.' : errorMessage(error));
} })
.finally(() => { if (!canceled) setLoading(false); });
return () => { canceled = true; };
}, [revision]);
return <main className="admin-shell">
<header className="admin-header"><div><a className="admin-return" href="/admin">Administration</a><h1>Room backups</h1></div>
<Button variant="outline" disabled={loading} onClick={() => { setOwner(null); setLoading(true); setRevision(value => value + 1); }}>Check access again</Button></header>
<p>Owner-only snapshots preserve a room without changing live play. Backups cannot be restored from this page.</p>
<p role="note" className="admin-notice">Privacy: downloaded snapshots contain private game state and may contain access credentials. Keep files secure; do not share them with players or upload them to public storage. This page shows metadata only, never the snapshot contents.</p>
{notice && <p role="alert" className="admin-notice">{notice}</p>}
{loading ? <output>Checking owner access…</output> : owner ?
<AdminBackups key={owner.id} accountId={owner.id} onDenied={() => {
setOwner(null); setNotice('Owner access changed or expired. Sign in again before using room backups.');
}} /> : <p><a className="admin-room-link" href="/admin">Sign in to administration</a></p>}
</main>;
}
+1
View File
@@ -124,6 +124,7 @@ export default function Administration() {
<section aria-labelledby="admin-rooms-title">
<div className="admin-section-heading"><div><h2 id="admin-rooms-title">Rooms</h2><p className="admin-secondary">Public room details. Cards, sealed choices and private discussion stay hidden.</p></div>
<div className="admin-room-actions">{account.role !== 'viewer' && <Button disabled={controlsBusy} onClick={() => { setSelectedDiscussion(null); setSelectedSeatAi(null); setSelectedRoom(null); setSelectedLobby(null); setSelectedRemoval(null); setSelectedClosure(null); setSelectedArchive(null); setCreatingRoom(true); }}>Create a room</Button>}
{account.role === 'owner' && <a className="admin-room-link" href="/admin/backups">Room backups</a>}
<Button variant="outline" disabled={controlsBusy} onClick={() => void load(applied, directory?.page ?? 1)}><RefreshCw aria-hidden="true" /> Refresh</Button></div></div>
{creatingRoom && account.role !== 'viewer' && <AdminRoomCreation key={account.id} accountId={account.id}
onClose={() => setCreatingRoom(false)} onDenied={accessChanged} onBusyChange={setOperationBusy}