import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { readSpaceSuggestions } from "yt-dlp-transcript-common/controller/spaceScan"; import { diskNeedOrder } from "yt-dlp-transcript-common/lib/spaceSuggestions"; import { spaceScanJob, spaceView } from "../../../cleanup/space/lib/loadSpace"; import { readRoute } from "../_read"; import { opsFail } from "../_lib"; export const dynamic = "force-dynamic"; // GET [?disk=] // -> { ok, computedAt, ageSeconds, tookMs, jobId?, scan: {jobId, status} | null, // floorBytes, disks (most in need first), disk, groups (the page's // order: caption compression leads the corpus disk, then by subtotal), // suggestions (for `disk`, default the fullest, biggest saving first), // overflow, held, refused, // unmanaged, notScanned, compactionAt } // // /cleanup/space's list (lane space-suggestions): what the last space scan // (`space-scan`, controller/spaceScan.ts) found — every disk the archive // writes to, how much of it is the archive's, and what would free space on // each, each suggestion with its `actions` (the existing ops call that does // it: `pnpm ops --json `), its `basis` (measured or an estimate, // and from what) and what it loses. It READS THE FILE ONLY; with no scan yet // it answers `computedAt: null`. `space-scan` runs one. export async function GET(request: Request) { return readRoute(request, ["disk"], async (q) => { const result = await readSpaceSuggestions(getPaths()); const scan = spaceScanJob(); if (!result) return { computedAt: null, scan }; const disk = q.get("disk")?.trim() || null; if (disk && !result.disks.some((d) => d.id === disk)) { return opsFail(`no disk "${disk}" in the last scan — it knows ${diskNeedOrder(result.disks, result.floorBytes).map((d) => d.id).join(", ")}`); } return { ...spaceView(result, disk), ageSeconds: Math.max(0, Math.round((Date.now() - Date.parse(result.computedAt)) / 1000)), scan, }; }); }