import { SPACE_SCAN_BODY_KEYS } from "yt-dlp-transcript-common/controller/spaceScan"; import { enqueueSpaceScanJob } from "../../../cleanup/space/lib/spaceJob"; import { NextResponse } from "next/server"; import { spaceScanJob } from "../../../cleanup/space/lib/loadSpace"; import { jobResponse, ops, optBool } from "../_lib"; export const dynamic = "force-dynamic"; // POST { compaction? } -> { ok: true, jobId } // // The space scan (lane space-suggestions, controller/spaceScan.ts) as a // `space-scan` job on its own machine-wide queue: every disk the archive // writes to — the corpus disk, each storage location, the saved-video store's, // the site builds' and umtool's reports' — measured (allocated bytes, each // inode once, a hard-linked file never counted as freed, an unmounted or // unanswering drive unknown and never empty), and what would free space on // each through the writers that already exist, into // `transcripts/.space-suggestions.json` (`get space-suggestions` reads it). // It only reads: nothing is removed, moved or fetched. `"compaction": false` // skips the compaction selector's pass (one ffprobe per saved container not // seen unchanged before) and carries the last scan's compaction rows. While a // scan is queued or running nothing more is queued: the answer is that job, // `{ok: true, jobId, alreadyQueued: true}`. export async function POST(request: Request) { return ops(request, SPACE_SCAN_BODY_KEYS, async (body) => { const compaction = optBool(body, "compaction"); const there = spaceScanJob(); if (there) return NextResponse.json({ ok: true, jobId: there.jobId, alreadyQueued: true, status: there.status }); return jobResponse(await enqueueSpaceScanJob(compaction === false ? { compaction: false } : {})); }); }