// IS THIS AN INSTAGRAM POSTS CHANNEL? One predicate, pure and client-safe, for // everything that must agree about it: the fetch (controller/fetchPosts.ts), // the action that queues it, the scheduler that would queue it // (jobs/syncScheduler.ts) and the boot's resume (jobs/resumeInterrupted.ts). // // ANY SIGN OF INSTAGRAM COUNTS — the platform the config names, the fetcher it // names, or its URL's host — because the fetch refuses a channel whose signs // disagree (fetcherPlatformMismatch) and everything else must hold back the // same channels the fetch would treat as Instagram's. Testing the config's // `platform` alone queued a channel with an instagram.com URL and no platform // every tick, to be refused every tick. import { detectPlatform } from "../detectPlatform.mjs"; export const INSTAGRAM_FETCHER_ID = "instagram-gallery-dl"; export const INSTAGRAM_QUEUE_KEY = "platform:instagram"; export type InstagramChannelSigns = { sourceKind?: string; platform?: string; postFetcher?: string; url?: string; }; export function isInstagramPostsChannelConfig(config: InstagramChannelSigns | null | undefined): boolean { if (!config || config.sourceKind !== "social") return false; return ( config.platform === "instagram" || config.postFetcher === INSTAGRAM_FETCHER_ID || detectPlatform(config.url) === "instagram" ); } // An Instagram fetch runs on Instagram's queue and no other: a queue override // would run it beside the job already there, with no gap between them. export const INSTAGRAM_QUEUE_REFUSAL = (slug: string, asked: string) => `${slug} is an Instagram channel: its jobs run on ${INSTAGRAM_QUEUE_KEY} and nowhere else (one at a time, ten minutes apart), ` + `so the queue override "${asked}" is refused. Leave the queue at its default.`; // Why a queue override is refused for this channel, or null. export function instagramQueueProblem( slug: string, config: InstagramChannelSigns | null | undefined, override: string | undefined, ): string | null { if (override === undefined || !isInstagramPostsChannelConfig(config)) return null; return override.trim() === INSTAGRAM_QUEUE_KEY ? null : INSTAGRAM_QUEUE_REFUSAL(slug, override); }