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 (
{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." )}
Nothing the scan found frees space here.
} {groups.map((g) => (And {o.count.toLocaleString("en-US")} more ({formatBytes(o.bytes)}) {o.link ? ( <> {" "} — {o.link.label} > ) : null}
))}{u.command}
>
) : null}
{u.link ? (
<>
{" "}
— {u.link.label}
>
) : null}
{formatBytes(u.bytes)}
{u.disk ? ` · ${diskLabel[u.disk] ?? u.disk}` : ""}
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.