"use server"; // What is left of the actionable census's actions: the two GLOBAL incomplete- // transcript fixes, which act on every channel the census lists. The duplicate // and media-scan actions moved to ../../review/actions with the page that runs // them; the report refresh moved to ../../channels/actions. import { revalidatePath } from "next/cache"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { clearIncompleteTranscriptsAction, enableAutoRunners, redownloadIncompleteBucketAction, } from "../../channels/[slug]/incompleteTranscriptActions"; import { loadActionableSummary } from "./loadActionable"; export type GlobalIncompleteResult = | { ok: true; channels: number; affected: number } | { ok: false; error: string }; // All channels with at least one truncated transcript right now. async function affectedIncompleteSlugs(): Promise { const summary = await loadActionableSummary(getPaths()); return summary.incompleteTranscripts.map((r) => r.channel.slug); } // Clear & re-queue every truncated transcript across all channels, then enable // the auto-runners once. Destructive — the caller confirms first. export async function clearAllIncompleteTranscriptsAction(): Promise { const slugs = await affectedIncompleteSlugs(); if (slugs.length === 0) { return { ok: false, error: "No incomplete transcripts to clear." }; } let cleared = 0; for (const slug of slugs) { // Defer enabling the runners until the end so settings flip only once. const r = await clearIncompleteTranscriptsAction(slug, undefined, { enableRunners: false, }); cleared += r.succeeded; } await enableAutoRunners(); revalidatePath("/operations/[id]", "page"); return { ok: true, channels: slugs.length, affected: cleared }; } // Queue one batch re-fix job per affected channel (fire-and-forget — the jobs // keep running and surface in /jobs; cancel each stream so we don't hold them // open). export async function redownloadAllIncompleteTranscriptsAction(): Promise { const slugs = await affectedIncompleteSlugs(); if (slugs.length === 0) { return { ok: false, error: "No incomplete transcripts to fix." }; } let queued = 0; for (const slug of slugs) { const result = await redownloadIncompleteBucketAction(slug); if (result.ok) { void result.stream.cancel(); queued++; } } revalidatePath("/operations/[id]", "page"); return { ok: true, channels: slugs.length, affected: queued }; }