import { NextResponse } from "next/server"; import { watchXTrendingAction, type WatchSettingsAsk } from "../../../channels/[slug]/xTrendingActions"; import { ops, opsFail, optBool, optString, reqSlug } from "../_lib"; export const dynamic = "force-dynamic"; // POST { slug, topic, on, intervalMinutes?, hours?, shots?, tabs?, by? } // -> { ok: true, slug, topic, watch, sentence } // POST { slug, settings: {maxVideoMb?, intervalMinutes?, hours?, maxTopics?} } // -> { ok: true, slug, settings, sentence } // POST { slug, tick: true } // -> { ok: true, slug, scan, sentence } // // WATCH A TOPIC OF AN X TRENDING LIBRARY (lane x-trending-2). While a topic // is watched, its trending page is read again every `intervalMinutes` // (15–1440; default the library's, else 30) until `hours` from now (1–168; // else 48), each tick the SAME single `read-x-trending` job on X's queue, // started by the editor's own scan (once a minute; at most one read per scan; // none while a trending read, a reparse or a capture of ANY library waits its // turn: every library's ticks are one stream). A topic of // several trending pages reads one page per tick, in turn. At most // `maxTopics` topics of a library are watched at once (default 4). // // on true watches the topic (again: its terms change, its history // stays); false stops (the watch ends "switched off") // tabs the page's tabs each tick reads: ["top"], ["latest"] or both // (the default; both are read in the one job). // shots also screenshot every new post. Default: a new post's MEDIA only, // fetched at once from X's media CDN with no page opened // by "agent" (default) or "operator" // // A WATCH RUNS ONLY WHILE X'S COOKIE JAR IS UNDER ITS LIMIT (60 minutes). The // editor never refreshes the jar by itself, so a watch PAUSES when the jar // goes stale — X's jar-age alert goes up and /review lists the paused watches // — and resumes at the first scan after Refresh cookies on /cookies. It does // not cover a night nobody presses Refresh in. THE LIMIT IS THE WATCH'S OWN, // stricter than the one a person's job meets: whatever the login source, a // watch asks the profile's exported jar to be between 0 and the limit old (the // setting when above 0, else 60 minutes), and never ticks when settings // cannot be read. It is asked when a tick is queued AND AGAIN WHEN THE TICK'S // JOB STARTS (and when the capture that follows it is queued and starts): a // job waits its turn on X's queue, and a tick whose turn comes on a jar past // the limit is not read — no browser opens, the watch pauses, and it is no // strike against it. The X alert, X cooling down after a rate limit and a // missing profile pause it the same way. // // THREE READS IN A ROW THAT DO NOT END "read" (a rate limit, a 403, a page // that will not load) pause the watch as "failing". That pause does not end // by itself, and only the OPERATOR ends it: switch the watch on again with // `"by": "operator"` (the page's Watch button); an agent's ask is refused. // // A post a page showed before and does not show at a read whose capture shows // the page's end (the page asked for more FROM THE BOTTOM — the request carries // the previous answer's bottom cursor — and got nothing new, and no answer // failed or carried errors) is recorded "gone from the page at