import { safeRevalidate } from "../../lib/safeRevalidate"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { runManagedFunction, type StreamActionResult, } from "yt-dlp-transcript-common/jobs/streamCommand"; import { checkClipWindows, checkClipWindowsSummary, } from "yt-dlp-transcript-common/controller/checkClipWindows"; // ONE ENQUEUE OF THE CLIP-WINDOW SYNC CHECK, for its callers: the button on // /storage (and a channel's Storage panel) and the `/api/ops/check-windows` // adapter. Not in `actions.ts` for evictClipsJob.ts's reason: every non-type // export of a "use server" file is a server action, and a shared helper there // would be an unguarded enqueue on the wire. // // A JOB, like the eviction: a corpus-wide pass is a readdir of every video dir // and an ffprobe per window, it RENAMES, and the operator is owed a log naming // every window it set aside. `channelSlug` only for a one-channel run, so the // text guard has a channel to ask. export async function enqueueCheckClipWindows(opts: { slug?: string; video?: string; dryRun?: boolean; }): Promise { const paths = getPaths(); return runManagedFunction({ kind: "check-windows", // Parallel: it touches `clips/` only, and asks no platform. queueKey: "", paths, ...(opts.slug ? { channelSlug: opts.slug } : {}), ...(opts.slug && opts.video ? { videoId: opts.video } : {}), fn: async (onLog, signal) => { const where = opts.video ? `${opts.slug}/${opts.video}` : opts.slug ? `in ${opts.slug}` : "across every channel"; onLog( `${opts.dryRun ? "Listing" : "Checking"} fetched clip windows ${where} for a picture ` + `that runs off its sound${opts.dryRun ? " (dry run: nothing is renamed)" : ""}.`, ); const result = await checkClipWindows({ paths, ...(opts.slug ? { slug: opts.slug } : {}), ...(opts.video ? { video: opts.video } : {}), ...(opts.dryRun ? { dryRun: true } : {}), onLog, signal, }); onLog(checkClipWindowsSummary(result)); if (!opts.dryRun && result.setAside > 0) { safeRevalidate(["/storage"]); if (opts.slug) safeRevalidate([`/channels/${opts.slug}`]); } }, }); }