import { NextResponse } from "next/server"; import { renameChannelFromForm } from "../../../channels/actions"; import { opsFail, ops, reqSlug } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug: string, newSlug: string } // // The channel page's Danger → Rename, over HTTP. The form makes the operator // type the current slug to confirm; here the body naming `slug` IS that // confirmation, so it is passed through as the typed value and the action // applies every other rule unchanged — a busy channel (a running job, a lane // unit writing into data/, media in transition), a taken or invalid new slug. // // Answers { ok, slug: , warnings }. A warning is a non-fatal // metadata-migration problem after the directory moved: the form can only log // it, and this can say it. export async function POST(request: Request) { return ops(request, ["slug", "newSlug"], async (body) => { const slug = reqSlug(body, "slug"); const newSlug = reqSlug(body, "newSlug"); const fd = new FormData(); fd.set("confirmSlug", slug); fd.set("newSlug", newSlug); const result = await renameChannelFromForm(slug, fd); if (!result.ok) return opsFail(result.error); return NextResponse.json({ ok: true, slug: result.slug, from: slug, warnings: result.warnings, }); }); }