import { displayPath, displayText } from "yt-dlp-transcript-common/lib/privacy/privacy-server";
import ActionPlan from "@/components/system/ActionPlan";
import { Panel } from "@/components/ui/panel";
import { fmtAgo } from "@/lib/format";
import type { StorageRow } from "@/lib/system/storage-rows";
// ---------------------------------------------------------------------------
// Settings · system's maintenance (P5): what `umtool doctor`, `umtool index`
// and `umtool storage` say and do, on the page. Reading is free; every action
// that changes or moves anything is a plan first (ActionPlan): Confirm, or
// Keep it. Server-rendered; the plans are the client's.
// ---------------------------------------------------------------------------
type Roots = {
ok: boolean;
reports: { path: string; present: boolean };
media: { path: string; tiered: boolean; present: boolean; problem: string | null };
cache: { path: string; present: boolean; index: boolean };
oldCache: { path: string; present: boolean };
};
function Row({ k, children, bad = false }: { k: string; children: React.ReactNode; bad?: boolean }) {
return (
<>
{k}
{children}
>
);
}
export function RootsPanel({ roots }: { roots: Roots }) {
return (
umtool doctor} data-panel="roots" data-roots-ok={roots.ok ? "yes" : "no"}>
{displayPath(roots.reports.path)}
{roots.reports.present ? "" : " — not there"}
{roots.media.tiered ? displayPath(roots.media.path) : "= reports · UMTOOL_MEDIA_DIR unset"}
{roots.media.problem ? ` — ${displayText(roots.media.problem)}` : ""}
{displayPath(roots.cache.path)}
{roots.cache.index ? "" : " — no index yet"}
{roots.oldCache.present && {displayPath(roots.oldCache.path)} — not read; safe to delete
}
);
}
export function IndexPanel({ index }: { index: { ok: boolean; records: number; path: string | null; builtAt: number | null; stale: number } }) {
return (
umtool index} data-panel="index" data-index-records={index.records} data-index-stale={index.stale}>
{index.ok ? (
{index.records} records
{index.stale > 0 ? (
<>
, {index.stale} for projects that are gone
>
) : null}
{index.builtAt ? ` · rebuilt ${fmtAgo(index.builtAt)}` : ""}
) : (
No index — every read walks the disk.
)}
{index.path && {displayPath(index.path)}
}
);
}
const WORD: Record = { absent: "none", dir: "here", link: "on media", dangling: "DRIVE MISSING", other: "not a directory" };
export function StoragePanel({ rows, tiered, mediaRoot }: { rows: StorageRow[]; tiered: boolean; mediaRoot: string }) {
const outs = rows.filter((r) => r.out !== "absent");
return (
umtool storage · {tiered ? `media root ${displayPath(mediaRoot)}` : "no media root (UMTOOL_MEDIA_DIR unset)"}}
data-panel="storage"
className="lg:col-span-2 2xl:col-span-3"
>
{outs.length === 0 && rows.length === 0 ? (
No projects.
) : (
{rows.map((r) => (
-
{r.id}
out/ {WORD[r.out] ?? r.out}
{r.deliverables && (
deliverables {r.deliverables.mode ?? "INVALID"}
{r.deliverables.dirs ? ` · ${r.deliverables.dirs}` : ""}
)}
{tiered && r.out === "dir" && (
)}
{(r.out === "link" || r.out === "dangling") && (
)}
{r.deliverables && (tiered || r.deliverables.mode === "media") && (
)}
))}
)}
);
}