import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { isValidChannelSlug, readChannelConfig, readChannelSnapshot, } from "yt-dlp-transcript-common/controller/channels"; import { loadCleanupRow } from "../../../../cleanup/lib/loadCleanup"; import { opsFail } from "../../_lib"; import { readRoute } from "../../_read"; export const dynamic = "force-dynamic"; // GET /api/ops/cleanup/ // // One channel's row of the /cleanup ledger (`loadCleanupRow`), off its report: // what each sweep would reclaim — `transcribedBytes` (audio of videos that have // a transcript: "Clean audio"), `extraFormatsBytes`, `foreignBytes` (audio not // in the target format) — which OVERLAP and are never summed; what holds the // rest (`heldBytes`/`heldCounts`: no transcript, keep-latest, do-not-clean, // awaiting diarization); whether the channel is in the ledger's total // (`included`); and the failed-transcriptions list's length. `measured: false` // means the report predates the accounting: its zeros are unknowns. // // The sweeps themselves are `POST /api/ops/cleanup`. export async function GET( request: Request, { params }: { params: Promise<{ slug: string }> }, ) { const { slug } = await params; return readRoute(request, [], async () => { if (!isValidChannelSlug(slug)) { return opsFail(`"${slug}" is not a valid channel slug`); } const paths = getPaths(); const config = await readChannelConfig(paths, slug); if (!config) return opsFail(`Channel "${slug}" not found`, 404); const snapshot = await readChannelSnapshot(paths, slug); const row = await loadCleanupRow(paths, { slug, config, snapshot }); if (!row) return opsFail(`Channel "${slug}" not found`, 404); const { channel: _c, snapshot: _s, transcribeIds, autoSubsIds, ...rest } = row; void _c; void _s; return { slug, reportedAt: snapshot?.generatedAt ?? null, ...rest, // Counts, not the id lists: a bucket can hold thousands of ids. downloadedNoTranscript: transcribeIds.length, downloadedAutoSubsOnly: autoSubsIds.length, }; }); }