import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { enqueueSpaceScan } from "yt-dlp-transcript-common/controller/spaceScan"; import { safeRevalidate } from "../../../lib/safeRevalidate"; import { spaceScanJob } from "./loadSpace"; // ONE ENQUEUE OF THE SPACE SCAN, for /cleanup/space's Refresh and the // `/api/ops/space-scan` adapter. Not in `actions.ts` ("use server": every // export there is an endpoint), like storage/lib/evictClipsJob.ts. // // ONE AT A TIME, AND NEVER TWICE (review 1, 15): while a scan is queued or // running, a second Refresh queues nothing and answers with the one there is. export async function enqueueSpaceScanJob(opts: { compaction?: boolean } = {}): Promise { const there = spaceScanJob(); if (there) { return { ok: false, info: true, error: `A space scan is already ${there.status} (job ${there.jobId}): its result replaces this page's when it ends.` }; } return enqueueSpaceScan({ paths: getPaths(), // The settings as they are when the job STARTS (it may have queued). settings: () => getSettings(), ...(opts.compaction === false ? { compaction: false } : {}), onDone: () => safeRevalidate(["/cleanup", "/cleanup/space"]), }); }