import { NextResponse } from "next/server"; import { compactionMarkersAction } from "../../../saved-videos/compactActions"; import { ops, reqSlug, reqVideoId, type OpsBody, OpsInputError } from "../_lib"; export const dynamic = "force-dynamic"; // POST {} | { clear: { slug, id } } // -> { ok, markers: [{ slug, id, dir, live, why, marker }], cleared? } // // The "being compacted" markers (`/.compacting.json`, // lib/compactingMarker-server.ts): each one, LIVE (its compaction runs: same // kernel boot, host, pid and pid start time, its job running, younger than // 72 h) or STALE, and why. `clear` removes one video's marker when it is // stale; a live one is refused — cancel its job instead. Stale markers are // also swept at editor boot and at the start of every compaction run. function optClear(body: OpsBody): { slug: string; id: string } | undefined { if (body.clear === undefined) return undefined; if (!body.clear || typeof body.clear !== "object" || Array.isArray(body.clear)) { throw new OpsInputError('"clear" must be { "slug", "id" }'); } const c = body.clear as OpsBody; return { slug: reqSlug(c, "slug"), id: reqVideoId(c, "id") }; } export async function POST(request: Request) { return ops(request, ["clear"], async (body) => { const clear = optClear(body); const res = await compactionMarkersAction(clear ? { clear } : {}); return NextResponse.json({ ok: true, ...res }); }); }