// "IS THIS CHANNEL AN X TRENDING LIBRARY?", asked of the disk by the doors a // library is kept behind (lane x-trending, review 1): the report hosts, the // draft's post resolver, a research run's channel list. One small read of the // channel's config.json; the MARKER ALONE decides (lib/xTrending/config.ts // isXTrendingChannel), so a library whose kind or platform was edited by hand // is still one. SERVER-ONLY (node:fs). import path from "node:path"; import { readJsonFile, readJsonFileSync } from "../jsonFile-server"; import { isXTrendingChannel } from "./config"; const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/; function marked(value: unknown): boolean { return isXTrendingChannel(value && typeof value === "object" ? (value as { xTrending?: unknown }) : null); } export function isXTrendingLibrarySync(channelsDir: string | undefined, slug: string): boolean { if (!channelsDir || !SLUG.test(slug)) return false; const raw = readJsonFileSync(path.join(channelsDir, slug, "config.json")); return raw.ok && marked(raw.value); } export async function isXTrendingLibrary(channelsDir: string | undefined, slug: string): Promise { if (!channelsDir || !SLUG.test(slug)) return false; const raw = await readJsonFile(path.join(channelsDir, slug, "config.json")); return raw.ok && marked(raw.value); }