"use server"; // AN X SEARCH CHANNEL'S LEADS (release 38 lane S): "Archive this account" — // a `-x` channel on NO site through the New channel form's own path // (createChannelFromForm), its first post fetch started — and "Never archive" // (the handle into the search channel's `xSearch.exclude`, hidden from the // view) with its undo. The controllers' refusals, in their sentences // (common/controller/xSearchLeads.ts). No model, no request but the new // channel's fetch, which runs on X's queue like any other. import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { planArchiveXLead, readXSearchLeads, setXSearchLeadHidden, type XSearchLeadsView, } from "yt-dlp-transcript-common/controller/xSearchLeads"; import { isXTrendingLibrary } from "yt-dlp-transcript-common/lib/xTrending/library-server"; import { safeRevalidate } from "../../lib/safeRevalidate"; import { applyChannelFormPatch } from "../components/channelConfigToForm"; import { applyChannelPriorityPresetAction, createChannelFromForm, setChannelTierAction } from "../actions"; import { xLeadArchiveMode, xLeadSyncOffSentence } from "yt-dlp-transcript-common/lib/xSearch/leads"; export type XLeadActionResult = | { ok: true; slug?: string; jobIds?: string[]; exclude?: string[]; changed?: boolean; dryRun?: boolean; fields?: Record; syncOff?: boolean; sentence?: string } | { ok: false; error: string }; export async function readXSearchLeadsAction( slug: string, limit?: number, ): Promise { return readXSearchLeads(getPaths(), slug, limit !== undefined ? { limit } : {}); } // Archive this account: plan (refused when the account is archived already // or the slug is taken), then create through the form's path — on no site, // "Fetch posts now" ticked. `dryRun` answers the plan and creates nothing. export async function archiveXSearchLeadAction( slug: string, handle: string, opts: { name?: string; dryRun?: boolean; fetch?: boolean } = {}, ): Promise { const plan = await planArchiveXLead(getPaths(), slug, handle, opts.name); if (!plan.ok) return plan; if (opts.dryRun) return { ok: true, slug: plan.slug, fields: plan.fields, dryRun: true }; const fd = new FormData(); applyChannelFormPatch(fd, plan.fields); fd.set("slug", plan.slug); // From an X TRENDING LIBRARY's accounts (lane x-trending-publish) the press // makes the channel and asks X nothing, now or at the scheduler's next tick: // the channel is made with SYNC OFF (lib/xSearch/leads.ts xLeadArchiveMode // says why). The tier is written BEFORE the channel is, so there is no // moment at which the new channel exists and is due. From a search // channel's leads nothing changes: the first fetch starts unless `fetch: // false`, and no priority is written. const library = await isXTrendingLibrary(getPaths().channelsDir, slug); const mode = xLeadArchiveMode({ library, ...(opts.fetch !== undefined ? { fetch: opts.fetch } : {}) }); if (mode.fetchNow) fd.set("fetchPostsNow", "on"); if (mode.syncOff) { const paused = await setChannelTierAction([plan.slug], "paused"); if (paused?.error) return { ok: false, error: `The channel was not made: its sync could not be switched off first (${paused.error}).` }; } const created = await createChannelFromForm(fd); if (!created.ok) { // No channel: no entry for it either. if (mode.syncOff) await applyChannelPriorityPresetAction([plan.slug], "clear"); return { ok: false, error: created.error }; } safeRevalidate([`/channels/${slug}`, `/channels/${created.slug}`, "/channels"]); return { ok: true, slug: created.slug, jobIds: created.jobIds, ...(mode.syncOff ? { syncOff: true, sentence: xLeadSyncOffSentence(created.slug, handle) } : {}), }; } // Never archive (hidden: true) and its undo (hidden: false). export async function hideXSearchLeadAction( slug: string, handle: string, hidden: boolean, ): Promise { const res = await setXSearchLeadHidden(getPaths(), slug, handle, hidden); if (!res.ok) return res; safeRevalidate([`/channels/${slug}`]); return { ok: true, exclude: res.exclude, changed: res.changed }; }