// settings.privacy.hidePrivateSites in umtool (demo epic D4): which pieces and // projects home, /projects and /work leave out. The one notion of "private" // is a site's own (site.json `audience: "private"`, isPrivateSite); a piece is // private when it is an article of a private site, and a project when the // piece it belongs to (the piece graph's pieceOfProject) is. An article's own // `audience` is a different thing and hides nothing. // // A LIST FILTER, not access control: a private site's pages still open by URL. // Null while the setting is off or no site is private — every caller then // does exactly what it did before. // // SERVER ONLY. import { hidePrivateSites } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; import { isPrivateSite, listSites } from "yt-dlp-transcript-common/lib/site"; import { sitesPaths } from "./articles/sites"; import { ARTICLES_KEY } from "./articles/key.mjs"; import { pieceOfDecision, readPieceGraph, type PieceGraph } from "./pieces"; import type { Decision } from "./decisions"; export type PrivateFilter = { sites: Set; pieces: Set; projects: Set; }; /** The private sites' pieces and projects, or null when nothing is hidden. */ export async function privateFilter(graph?: PieceGraph): Promise { if (!hidePrivateSites()) return null; let sites: Set | null; try { sites = new Set(listSites(sitesPaths()).filter(isPrivateSite).map((s) => s.siteId)); } catch { // FAIL CLOSED (review round 1, S3): the sites cannot be read, so which // are private is unknown — every site's pieces are hidden. Home, /projects // and /work then show the article store's pieces and the projects no site // article claims. sites = null; } if (sites && !sites.size) return null; const g = graph ?? (await readPieceGraph()); if (!sites) sites = new Set(g.pieces.flatMap((p) => (p.site !== null && p.site !== ARTICLES_KEY ? [p.site] : []))); const pieces = new Set(g.pieces.filter((p) => p.site !== null && sites.has(p.site)).map((p) => p.id)); const projects = new Set([...g.pieceOfProject].filter(([, piece]) => pieces.has(piece)).map(([project]) => project)); return { sites, pieces, projects }; } /** Is this decision about a hidden piece or project? */ export function decisionIsPrivate(d: Decision, graph: PieceGraph, hide: PrivateFilter): boolean { if (hide.projects.has(d.project)) return true; const piece = pieceOfDecision(d, graph); return piece !== null && hide.pieces.has(piece); }