Add Back up now for Fragnet game servers

Operators can ask the game panel for a backup of a server whose plan has room for backups (Back up on the row, Back up now beside its backups). The panel makes it in the background; the page re-reads every 20 s until it is done. Refused here for a plan with no room, a suspended server, one already being backed up, or the same server within 30 s; the panel's own refusals (plan full, rate limit, permission) are shown in its words. Written to the audit log.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-06 19:48:46 +01:00
1 parent 31f4debb9a
commit f9991a49af
9 files changed
+326 -11

No files matched your search

+2
View File
@@ -3674,6 +3674,8 @@ export const api = {
fragnet: {
list: () => request<{ accounts: FragnetAccount[] }>("/api/fragnet"),
power: (integrationId: number, serverId: string, signal: FragnetSignal) => request<void>(`/api/fragnet/${integrationId}/servers/${serverId}/power`, { method: "POST", body: JSON.stringify({ signal }) }),
/** Asks the panel to make a backup of one game server now. It is made in the background. */
backup: (integrationId: number, serverId: string) => request<{ name: string; uuid: string | null }>(`/api/fragnet/${integrationId}/servers/${serverId}/backup`, { method: "POST" }),
refresh: (integrationId: number) => request<{ status: { ok: boolean; error: string | null } }>(`/api/fragnet/${integrationId}/refresh`, { method: "POST" }),
},
hetzner: {
+65 -5
View File
@@ -80,8 +80,14 @@ const SIGNAL_TEXT: Record<FragnetSignal, { verb: string; done: string; confirm:
kill: { verb: "Kill", done: "kill", confirm: "Kill {name}? It is stopped at once, without saving — unsaved progress is lost. Use it only when Stop does not work.", danger: true },
};
function Details({ s, panelUrl, canAct, onSignal }: { s: Server; panelUrl: string; canAct: boolean; onSignal: (s: Server, signal: FragnetSignal) => void }) {
/** Whether a backup of this server is being made now (one the panel has begun and not finished, from the last two hours). */
function backupInProgress(s: Server): boolean {
return (s.backups ?? []).some((b) => b.completedAt === null && Date.now() - Date.parse(b.createdAt ?? "") < 2 * 60 * 60_000);
}
function Details({ s, panelUrl, canAct, onSignal, onBackup, busy }: { s: Server; panelUrl: string; canAct: boolean; onSignal: (s: Server, signal: FragnetSignal) => void; onBackup: (s: Server) => void; busy: boolean }) {
const backups = s.backups ?? [];
const making = backupInProgress(s);
return (
<div className="row g-3">
<div className="col-lg-4">
@@ -127,7 +133,14 @@ function Details({ s, panelUrl, canAct, onSignal }: { s: Server; panelUrl: strin
</div>
</div>
<div className="col-lg-4">
<h5>Backups{s.backupLimit ? ` (${backups.filter((b) => b.completedAt !== null).length} of ${s.backupLimit})` : ""}</h5>
<div className="d-flex align-items-center gap-2 mb-2">
<h5 className="mb-0">Backups{s.backupLimit ? ` (${backups.filter((b) => b.completedAt !== null).length} of ${s.backupLimit})` : ""}</h5>
{canAct && s.backupLimit ? (
<button className="btn btn-sm ms-auto" disabled={busy || making} onClick={() => onBackup(s)} title={making ? "One is already being made" : "Ask the panel to make a backup now"}>
{making ? "Being made…" : "Back up now"}
</button>
) : null}
</div>
{s.backups === null && <div className="text-secondary small">They could not be listed (the key may not be allowed to).</div>}
{s.backups !== null && backups.length === 0 && <div className="text-secondary small">{s.backupLimit ? "None has been made." : "This plan has none."}</div>}
<ul className="list-unstyled mb-0">
@@ -176,7 +189,7 @@ function Details({ s, panelUrl, canAct, onSignal }: { s: Server; panelUrl: strin
);
}
function ServerRow({ a, s, readAt, canAct, open, onToggle, onSignal, busy }: { a: FragnetAccount; s: Server; readAt: string; canAct: boolean; open: boolean; onToggle: () => void; onSignal: (s: Server, signal: FragnetSignal) => void; busy: boolean }) {
function ServerRow({ a, s, readAt, canAct, open, onToggle, onSignal, onBackup, busy }: { a: FragnetAccount; s: Server; readAt: string; canAct: boolean; open: boolean; onToggle: () => void; onSignal: (s: Server, signal: FragnetSignal) => void; onBackup: (s: Server) => void; busy: boolean }) {
const main = s.allocations[0];
const problems = a.problems.filter((p) => p.serverId === s.id);
const running = s.state === "running" || s.state === "starting" || s.state === "stopping";
@@ -246,6 +259,11 @@ function ServerRow({ a, s, readAt, canAct, open, onToggle, onSignal, busy }: { a
</button>
</>
)}
{s.backupLimit ? (
<button className="btn btn-sm" disabled={busy || backupInProgress(s)} onClick={() => onBackup(s)} title={backupInProgress(s) ? "One is already being made" : "Ask the panel to make a backup now"}>
{backupInProgress(s) ? "Backing up…" : "Back up"}
</button>
) : null}
</div>
)}
</td>
@@ -253,7 +271,7 @@ function ServerRow({ a, s, readAt, canAct, open, onToggle, onSignal, busy }: { a
{open && (
<tr>
<td colSpan={6} className="bg-body-tertiary">
<Details s={s} panelUrl={a.panelUrl} canAct={movable} onSignal={onSignal} />
<Details s={s} panelUrl={a.panelUrl} canAct={movable} onSignal={onSignal} onBackup={onBackup} busy={busy} />
</td>
</tr>
)}
@@ -291,6 +309,48 @@ function Card({ a, canAct, reload }: { a: FragnetAccount; canAct: boolean; reloa
}
}
// While a backup is being made, read the account again every twenty seconds, so the page shows when it is done (how long it takes depends on the game).
const making = !!s?.servers.some(backupInProgress);
useEffect(() => {
if (!canAct || !making) return;
const t = setInterval(() => {
void api.fragnet
.refresh(a.id)
.catch(() => undefined)
.finally(reload);
}, 20_000);
return () => clearInterval(t);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [canAct, making, a.id]);
async function backUp(server: Server) {
const used = server.backups?.filter((b) => b.completedAt !== null).length ?? null;
const ok = await confirmDialog({
title: `Back up ${server.name}`,
message: `Ask the game panel to make a backup of ${server.name} now? It is made in the background while the game keeps running, and a large one can take a few minutes.${server.backupLimit ? ` It counts towards the ${server.backupLimit} the plan allows${used !== null ? ` (${used} made)` : ""} — if the plan is full the panel will refuse, and one has to be deleted in the panel first.` : ""}`,
confirmLabel: "Back up now",
});
if (!ok) return;
setBusy(true);
try {
await api.fragnet.backup(a.id, server.id);
toast.success(`Asked the panel to back up ${server.name}.`);
// It shows as "being made" once the panel has begun it; the effect above keeps reading until it is done.
setTimeout(() => {
void api.fragnet
.refresh(a.id)
.catch(() => undefined)
.finally(() => {
setBusy(false);
reload();
});
}, 4000);
} catch (err) {
setBusy(false);
toast.error(readableError(err));
}
}
return (
<div className="card mb-3">
<div className="card-header">
@@ -366,7 +426,7 @@ function Card({ a, canAct, reload }: { a: FragnetAccount; canAct: boolean; reloa
</thead>
<tbody>
{s.servers.map((x) => (
<ServerRow key={x.id} a={a} s={x} readAt={s.updatedAt} canAct={canAct} open={open === x.id} onToggle={() => setOpen(open === x.id ? null : x.id)} onSignal={(sv, sig) => void signal(sv, sig)} busy={busy} />
<ServerRow key={x.id} a={a} s={x} readAt={s.updatedAt} canAct={canAct} open={open === x.id} onToggle={() => setOpen(open === x.id ? null : x.id)} onSignal={(sv, sig) => void signal(sv, sig)} onBackup={(sv) => void backUp(sv)} busy={busy} />
))}
{s.servers.length === 0 && (
<tr>