import type { Metadata } from "next"; import Link from "next/link"; import { formatBytes } from "yt-dlp-transcript-common/lib/format"; import { ageText, diskNeedOrder, diskSuggestedBytes, fullestDiskId, groupSuggestions, leadKindsFor, suggestionsForDisk, usedPercent, type SpaceArchiveShare, type SpaceDisk, } from "yt-dlp-transcript-common/lib/spaceSuggestions"; import { CleanupTabs } from "../components/CleanupTabs"; import { SpaceRefresh } from "./components/SpaceRefresh"; import { SpaceRow } from "./components/SpaceRow"; import { loadSpace } from "./lib/loadSpace"; // FREE UP SPACE (lane space-suggestions): every disk the archive writes to, // fullest first, and what would free space on the one picked — each through // the writer that already exists. Everything here is the last space scan's // file (controller/spaceScan.ts) plus each disk's free space now; the page // never walks, stats the corpus or probes a container. export const dynamic = "force-dynamic"; export const metadata: Metadata = { title: "Free up space" }; const SHARE: { key: keyof SpaceArchiveShare; label: string; color: string }[] = [ { key: "media", label: "Media", color: "var(--chart-1)" }, { key: "text", label: "Text", color: "var(--chart-2)" }, { key: "clips", label: "Clip windows", color: "var(--chart-3)" }, { key: "store", label: "Saved videos", color: "var(--chart-4)" }, { key: "playable", label: "Playable copies", color: "var(--chart-5)" }, { key: "builds", label: "Site builds", color: "var(--chart-2)" }, { key: "reports", label: "umtool reports", color: "var(--chart-3)" }, { key: "other", label: "Index and other", color: "var(--chart-4)" }, ]; export default async function SpacePage({ searchParams }: { searchParams: Promise<{ disk?: string }> }) { const { disk: diskParam } = await searchParams; const { result, live, job } = await loadSpace(); const disks = result ? diskNeedOrder(result.disks, result.floorBytes) : []; const fullest = result ? fullestDiskId(result.disks, result.floorBytes) : null; const selected = disks.find((d) => d.id === diskParam && d.status === "ok")?.id ?? fullest; const diskLabel = Object.fromEntries(disks.map((d) => [d.id, d.label])); const list = result && selected ? suggestionsForDisk(result, selected) : []; const groups = groupSuggestions(list, { lead: selected ? leadKindsFor(selected) : [] }); const overflow = result?.overflow.filter((o) => o.disk === selected) ?? []; return (

Cleanup

{result ? ( <> Scanned {ageText(result.computedAt)} ({Math.round(result.tookMs / 1000)} s) {result.compactionAt && result.compactionAt !== result.computedAt ? ` · compaction rows from ${ageText(result.compactionAt)}` : ""} ) : ( "No scan yet." )}

{result && ( <>
{disks.map((d) => ( ))}

{selected ? `What frees space on ${diskLabel[selected] ?? selected}` : "No disk to free"} {selected && list.length > 0 && ( ~{formatBytes(diskSuggestedBytes(list))}, each file once )}

{groups.length === 0 &&

Nothing the scan found frees space here.

} {groups.map((g) => (

{g.label}

{g.bytes > 0 ? formatBytes(g.bytes) : g.laterLow > 0 ? `later ~${formatBytes(g.laterLow)}–${formatBytes(g.laterHigh)}` : "—"}
    {g.rows.map((s) => ( ))}
{overflow .filter((o) => o.kind === g.kind) .map((o) => (

And {o.count.toLocaleString("en-US")} more ({formatBytes(o.bytes)}) {o.link ? ( <> {" "} — {o.link.label} ) : null}

))}
))}
{result.held.length > 0 && (
Held: not offered ({result.held.length})
    {result.held.map((h) => (
  • {h.what}: {h.why} {h.link ? ( <> {" "} — {h.link.label} ) : null} {h.bytes !== null ? formatBytes(h.bytes) : "—"} {h.disk ? ` · ${diskLabel[h.disk] ?? h.disk}` : ""}
  • ))}
)} {result.refused.length > 0 && (
Saved videos the compaction selector does not pick ({formatBytes(result.refused.reduce((n, g) => n + g.bytes, 0))})
    {result.refused.map((g) => (
  • {g.group}: {g.count.toLocaleString("en-US")} container(s) {formatBytes(g.bytes)} Biggest:{" "} {g.examples.map((e, i) => ( {i ? ", " : ""} {e.slug}/{e.id} {" "} {formatBytes(e.bytes)} ))}
  • ))}
)} {result.unmanaged.length > 0 && (
The archive's, with no writer here ({formatBytes(result.unmanaged.reduce((n, u) => n + u.bytes, 0))})
    {result.unmanaged.map((u) => (
  • {u.what}: {u.owner} {u.command ? ( <> {" "} — {u.command} ) : null} {u.link ? ( <> {" "} — {u.link.label} ) : null} {formatBytes(u.bytes)} {u.disk ? ` · ${diskLabel[u.disk] ?? u.disk}` : ""}
  • ))}
)} {result.notScanned.length > 0 && (
Channels not scanned ({result.notScanned.length})
    {result.notScanned.map((n) => (
  • {n.slug}: {n.why}
  • ))}
)}

Each button runs the existing writer for its kind, which refuses what it refuses when it runs.{" "} pnpm ops get space-suggestions answers the same list.

)}
); } function DiskCard({ d, free, fullest, selected, floor }: { d: SpaceDisk; free: number | null; fullest: boolean; selected: boolean; floor: number }) { if (d.status !== "ok") { return (
{d.label} {d.status === "not-mounted" ? "Not mounted" : "Not answering"} {d.detail && {d.detail}}
); } const size = d.sizeBytes ?? 0; const pct = usedPercent(d, free); const share = d.archive; const seg = (n: number) => (size > 0 ? `${(n / size) * 100}%` : "0%"); const used = size > 0 && free !== null ? size - free : 0; const notArchive = Math.max(0, used - (d.archiveBytes ?? 0)); return (
{d.label} {fullest && fullest}
{d.mountpoint ?? "?"} · {d.roles.join(", ")}
{share && SHARE.map((c) => )}
{free !== null ? `${formatBytes(free)} free` : "free ?"} of {size ? formatBytes(size) : "?"} {pct !== null ? ` · ${pct} % used` : ""} {floor > 0 && free !== null && free < floor ? " · under the floor" : ""} The archive's: {formatBytes(d.archiveBytes ?? 0)} {share ? ` (${SHARE.filter((c) => share[c.key] > 0) .map((c) => `${c.label.toLowerCase()} ${formatBytes(share[c.key])}`) .join(", ")})` : ""} {" · "}not the archive's: {formatBytes(notArchive)} {d.detail && {d.detail}} ); }