"use server"; // THE X RUN CONSOLE's actions (/review, lane x-console): read the console, // start a run over the picked channels in the picked order, resume a deferred // one. The job and its rules are common/controller/xRun.ts; nothing here asks // X anything or refreshes the jar. import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { queueXRun, xRunConsole, type XRunConsole, type XRunRequest, } from "yt-dlp-transcript-common/controller/xRun"; import { safeRevalidate } from "../lib/safeRevalidate"; // The job, as the replay table and the ops route take it. export async function xRunAction(req: XRunRequest): Promise { return queueXRun({ paths: getPaths(), req, onChannelDone: (slug) => safeRevalidate([`/channels/${slug}`]), }); } export type XRunStartResult = { ok: true; jobId: string; run: string } | { ok: false; error: string; run?: string }; async function started(res: StreamActionResult & { run?: string }): Promise { if (!res.ok) return { ok: false, error: res.error, ...(res.run ? { run: res.run } : {}) }; // The console follows the run's state file, not the stream. void res.stream.cancel(); return { ok: true, jobId: res.jobId, run: res.run! }; } export async function startXRunAction(channels: string[], limit?: number): Promise { return started(await xRunAction({ channels, ...(limit !== undefined ? { limit } : {}) })); } export async function resumeXRunAction(run: string): Promise { return started(await xRunAction({ resume: run })); } export async function xRunConsoleAction(run?: string): Promise { return xRunConsole(getPaths(), run); }