Pass 3 next slice: snapshot polish, analytics depth, player drawer

- Snapshots now include recursive sizeBytes (lib/snapshots.ts dirSize),
  rendered as a badge next to mod count.
- Snapshot restore/delete is now type-to-confirm: click Restore/Delete,
  type the literal snapshot name, press Enter or click Confirm. Esc
  cancels, matches the existing wizard Esc handler.
- Analytics card:
  - Uptime ring showing % of datapoints with tps>0 (color-graded
    green/amber/red) + numeric % over selected range.
  - Peak-player marker dot on the Players sparkline + peak caption.
  - "Online now" player list (up to 8) with small PlayerAvatar badges,
    sourced from the latest analytics entry's players[] array.
- Player profile drawer (new):
  - Slide-in right panel opened by clicking any PlayerAvatar.
  - Shows Online / Op / Whitelisted / Banned badges, UUID, ban reason.
  - Quick toggles for op/deop, whitelist add/remove, ban (with reason
    input) and pardon — reuses /api/players POST contract.
  - Global event bus (lib/events.ts) decouples avatars from drawer.
  - Esc / backdrop / close-button dismiss.
- PlayerAvatar now renders as a <button> by default (stopPropagation on
  click, focus-visible ring); pass interactive={false} to opt out (used
  inside the drawer itself).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hurkicorgi 2026-04-13 05:39:32 -06:00
parent a011423017
commit 19d66c2de6
7 changed files with 589 additions and 109 deletions

21
lib/events.ts Normal file
View file

@ -0,0 +1,21 @@
export type AppEvents = {
"player:open": { name: string };
};
export function dispatchAppEvent<K extends keyof AppEvents>(
name: K,
detail: AppEvents[K]
): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new CustomEvent(name, { detail }));
}
export function onAppEvent<K extends keyof AppEvents>(
name: K,
handler: (detail: AppEvents[K]) => void
): () => void {
if (typeof window === "undefined") return () => {};
const listener = (e: Event) => handler((e as CustomEvent<AppEvents[K]>).detail);
window.addEventListener(name, listener);
return () => window.removeEventListener(name, listener);
}

View file

@ -4,6 +4,7 @@ import {
readdirSync,
copyFileSync,
rmSync,
statSync,
writeFileSync,
readFileSync,
unlinkSync,
@ -11,6 +12,22 @@ import {
import { join } from "path";
import { MODS_DIR, CLIENT_MODS_DIR, MOD_METADATA_FILE } from "./constants";
function dirSize(dir: string): number {
let total = 0;
try {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const p = join(dir, entry.name);
if (entry.isDirectory()) total += dirSize(p);
else if (entry.isFile()) {
try {
total += statSync(p).size;
} catch {}
}
}
} catch {}
return total;
}
const SNAPSHOTS_DIR = "/home/minecraft/server/snapshots";
const MAX_SNAPSHOTS = 10;
@ -19,6 +36,7 @@ export type SnapshotMeta = {
createdAt: string;
modCount: number;
mods: string[];
sizeBytes?: number;
};
function ensureDir(dir: string) {
@ -133,7 +151,8 @@ export function listSnapshots(): (SnapshotMeta & { dirName: string })[] {
const meta = JSON.parse(
readFileSync(join(SNAPSHOTS_DIR, dirName, "meta.json"), "utf8")
) as SnapshotMeta;
return { ...meta, dirName };
const sizeBytes = dirSize(join(SNAPSHOTS_DIR, dirName));
return { ...meta, dirName, sizeBytes };
})
.sort(
(a, b) =>