import { fetchPostsAction } from "../../../channels/[slug]/socialActions"; import { jobResponse, ops, optBool, optPositiveInt, optString, reqSlug, } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, full?, older?, floor?, from?, force?, limit?, pages?, queueKey? } -> { ok: true, jobId } // // `pages` caps how many pages a run reads, for a channel read page by page (a // forum thread: its latest N pages). // // A social channel's "Fetch posts" button, over HTTP — and its "Re-fetch full // history" (`full`) and "Fetch older posts" (`older`, with an optional `floor` // date, YYYY-MM-DD, that the walk stops at, and an optional `from` date it // starts afresh at, replacing its saved position). The job runs on the platform's // queue, as the buttons' does. // // Every refusal is the action's own sentence: a channel that is not a social // one, `full` and `older` together, a fetcher with no older walk, a floor // without `older` or that is not a date, `force` without `older`, and an older // walk over an account that shows no posts — nothing archived, and the last // timeline fetch read none — unless `force` is true. export async function POST(request: Request) { return ops( request, ["slug", "full", "older", "floor", "from", "force", "limit", "pages", "queueKey"], async (body) => { const slug = reqSlug(body, "slug"); return jobResponse( await fetchPostsAction( slug, optString(body, "queueKey"), optBool(body, "full"), optPositiveInt(body, "limit"), optBool(body, "older"), optString(body, "floor"), optBool(body, "force"), optPositiveInt(body, "pages"), optString(body, "from"), ), ); }, ); }