"use server"; // IMPORT ONE POST (release 27 S3b): one X status or one Bluesky post, by its // URL, into a posts channel of that platform (common/social/importPost.ts). // Refused HERE, before a job exists, with the controller's sentences: not a // post URL, no such channel, not a posts channel, a channel of another // platform or whose fetcher cannot read one post, another account's post, the // platform held or cooling down. The read runs as an `import-post` job on the // channel's platform queue, so it never runs beside a fetch of the same // source; its log ends with `@@import-post {…}`. import { safeRevalidate } from "../../lib/safeRevalidate"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { downloadQueueKey } from "yt-dlp-transcript-common/lib/queueKeys"; import { detectPlatform } from "yt-dlp-transcript-common/lib/platform"; import { runManagedFunction, type StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand"; import { IMPORT_POST_RESULT_MARKER, importPost, importPostHeld, planImportPost, } from "yt-dlp-transcript-common/social/importPost"; export async function importPostAction(slug: string, url: string): Promise { const paths = getPaths(); const planned = await planImportPost(paths, slug, url); if (!planned.ok) return { ok: false, error: planned.error }; const { config } = planned.plan; const platform = detectPlatform(config.url) ?? "unknown"; const held = await importPostHeld(paths, platform); if (held) return { ok: false, info: true, error: held }; return runManagedFunction({ kind: "import-post", queueKey: downloadQueueKey(config), paths, channelSlug: slug, fn: async (onLog, signal) => { const result = await importPost({ paths, slug, url, settings: getSettings(), onLog, signal }); onLog(`${IMPORT_POST_RESULT_MARKER}${JSON.stringify(result)}`); safeRevalidate([`/channels/${slug}`]); if (!result.ok) throw new Error(result.error ?? "Post import failed"); }, }); }