import { deleteIteration, planIterationDelete } from "yt-dlp-transcript-common/lib/report/delete"; import { OpsInputError, ops, optBool, reqString } from "../_lib"; import { articleDeleteAnswer, articleDeleteOptions } from "../_articleDelete"; export const dynamic = "force-dynamic"; // POST { id: string, n: number, dryRun?: boolean } // -> { ok, applied, plan, removed?, failed? } // // DELETE ONE ITERATION of an article (release 27 follow-up), as `archilyzer // reports delete --iteration ` does: `iterations//` and its video // project, through lib/report/delete.ts under the article registry's lock; its // number is retired. `dryRun` answers the plan and writes nothing. Refused // (409, with the plan; no override): the current article, the iteration its // report.json came from, the current video, a queued or running one, and one // another iteration revises or copies. export async function POST(request: Request) { return ops(request, ["id", "n", "dryRun"], async (body) => { const id = reqString(body, "id"); const n = body.n; if (typeof n !== "number" || !Number.isInteger(n) || n < 1) throw new OpsInputError('"n" is an iteration number (1, 2, …)'); const opts = articleDeleteOptions(); return articleDeleteAnswer(optBool(body, "dryRun") === true, false, () => planIterationDelete(id, n, opts), () => deleteIteration(id, n, opts)); }); }