import { NextResponse } from "next/server"; import { publishXTrendingAction } from "../../../channels/[slug]/xTrendingActions"; import { ops, opsFail, optBool, optString, reqSlug, reqString } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, topic, dryRun: true, channel? } // -> { ok: true, slug, dryRun: true, library, topic: {id, title}, channel, // creates, sites: [siteId], kept, posts, ids, already, // movedIn: [{id, by, from}], files, bytes, mismatched: [{id, name}], // textOnly: [ids], noLongerKept: [ids], inFlight?, confirm, sentence } // POST { slug, topic, confirm, by: "operator", channel? } // -> the same, dryRun: false: published // // PUBLISH A TOPIC OF AN X TRENDING LIBRARY (lane x-trending-publish): the // topic's posts whose judgement IN FORCE is KEEP BY THE OPERATOR (their own // entry, or their thread's) are written into an ORDINARY posts channel — // `channel`, a slug of the topic's name unless the ask gives one, fixed at // the first publish (renaming the topic does not fork it). An agent's keep is // a suggestion and is not published. // // THE CHANNEL IS ON NO SITE: adding it to one is the operator's separate act // (`pnpm ops site-config`, /sites). It names nothing of the library: no // judgement, note, read, watch or "gone from the page" mark, and its files // are COPIES (the library keeps its own; a purge of the library and a delete // of the channel do not reach each other). Nothing fetches it afterwards. // // TWO STEPS, AND THE SECOND IS THE OPERATOR'S. `dryRun: true` writes nothing // and says exactly what would be written: the slug, whether the channel is // made, `posts` to add (`ids`), `files` and `bytes` to copy, `textOnly` (kept // posts with no capture yet: published as their words; a later publish adds // the files) and `noLongerKept` (published before, since dropped: reported, // never removed). It also says what the operator should know before the // press: `sites`, THE SITES THE CHANNEL IS ALREADY ON ("these posts go public // at its next build"); `movedIn`, the posts to publish that somebody MOVED // into this topic and who did (an agent may move posts); and `mismatched`, // files whose bytes are no longer what their capture recorded (not copied). // The `confirm` covers the sites too: a channel put on a site after the dry // run refuses the publish. The publish carries the dry run's `confirm` and `by: // "operator"`; if anything it would write changed in between, it is refused // and nothing is written. An agent's publish is refused: it may ask for the // dry run. // // RE-PUBLISHING adds newly kept posts and files and removes nothing. // // Refused with a sentence: no such channel, not a library, no such topic, no // post kept by the operator, a publish with no `confirm` or not by the // operator, a `confirm` that no longer matches, A READ, A REPARSE OR A // CAPTURE OF THE LIBRARY QUEUED OR RUNNING (a dry run then says `inFlight: // true`), a `channel` other than the one the topic was published into, and A // CHANNEL OF THAT SLUG THIS PUBLISH DID NOT MAKE (one the library has no // record of, one with a source of its own, one holding a post this topic // never published, or one that is not the very directory this publish made: // a channel deleted and made again by hand, even empty, is refused; so is a // bare directory of the slug). export async function POST(request: Request) { return ops(request, ["slug", "topic", "channel", "dryRun", "confirm", "by"], async (body) => { const dryRun = optBool(body, "dryRun"); const channel = optString(body, "channel"); const confirm = optString(body, "confirm"); const result = await publishXTrendingAction({ slug: reqSlug(body, "slug"), topic: reqString(body, "topic"), ...(channel !== undefined ? { channel } : {}), ...(dryRun !== undefined ? { dryRun } : {}), ...(confirm !== undefined ? { confirm } : {}), ...(body.by !== undefined ? { by: body.by } : {}), }); if (!result.ok) return opsFail(result.error); return NextResponse.json(result); }); }