"use server"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { readSpaceSuggestions, readSpaceSuggestionsVersion } from "yt-dlp-transcript-common/controller/spaceScan"; import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { safeRevalidate } from "../../lib/safeRevalidate"; import { enqueueSpaceScanJob } from "./lib/spaceJob"; import { runSpaceSuggestion, type SpaceRunOutcome } from "./lib/runSpaceAction"; // /cleanup/space's two buttons. Refresh is the `space-scan` job (`pnpm ops // space-scan`); a suggestion's button names its KEY and runs the actions the // scan wrote for it, through the existing writers (lib/runSpaceAction.ts). export async function startSpaceScanAction(): Promise { return enqueueSpaceScanJob(); } export async function runSpaceSuggestionAction( key: string, opts: { dryRun?: boolean } = {}, ): Promise { const result = await readSpaceSuggestions(getPaths()); const fileVersion = result ? null : await readSpaceSuggestionsVersion(getPaths()); const out = await runSpaceSuggestion({ result, fileVersion, key, dryRun: opts.dryRun === true }); if (!out.dryRun && out.ok) safeRevalidate(["/cleanup", "/cleanup/space"]); return out; }