// WHAT LANE x-trending-2 ADDS TO A LIBRARY, PLANTED FOR THE PRIVACY PINS: a // judgement with a note, a watch, a captured post (its record, a shot, a // media file taken into the store with its address) and an availability // sidecar — each carrying a marker the pin then looks for in everything a // build, a report or a tool gives out. Written through the real writers, so // the layout is the one the editor leaves. Invented words throughout. import { mkdirSync, writeFileSync } from "node:fs"; import path from "node:path"; import { writePostAvailability } from "../../posts-server"; import { judgeXTrending } from "../judgements"; import { adoptXTrendingMedia, ensureXTrendingMediaIgnore } from "../mediaStore"; import { readXTrendingTopics, trendingDir, xTrendingPostsMediaDir } from "../store"; import { setXTrendingWatch } from "../watch"; export const SLICE2_MARKS = { note: "trendjudgenotemarkerh3v", media: "trendmediabytesmarkerk8d", address: "trendmediaaddressmarkerp5s", context: "trendcapturecontextmarkern2c", shot: "trendshotbytesmarkert6b", } as const; export const SLICE2_MARK_LIST: readonly string[] = Object.values(SLICE2_MARKS); // The names a build or a report must never carry a file of. // A library's captures directory (`trending///`), named here so the // pins under publish/ and bin/ need not spell it (postCapture.test.ts holds // every source there to naming it nowhere but the cited-capture copier). export const SLICE2_CAPTURES_DIRNAME = path.basename(xTrendingPostsMediaDir(".")); export const SLICE2_FILE_NAMES: readonly string[] = [ "judgements.json", "media-index.json", "watch.json", "media-store", "posts-availability.json", SLICE2_CAPTURES_DIRNAME, ]; // `postId` must be a post of the library, in a topic `topicId` that holds a page. export async function plantSlice2Library(libRoot: string, o: { postId: string; topicId: string }): Promise { await judgeXTrending(libRoot, { by: "operator", set: [{ id: o.postId, state: "keep", note: `kept ${SLICE2_MARKS.note}` }] }); await setXTrendingWatch(libRoot, { topics: await readXTrendingTopics(libRoot), topic: o.topicId, on: true, intervalMinutes: 30, hours: 48, by: "operator", maxTopics: 4, now: Date.parse("2026-11-18T10:00:00.000Z") }); const dir = path.join(xTrendingPostsMediaDir(libRoot), o.postId); mkdirSync(dir, { recursive: true }); writeFileSync(path.join(dir, `${o.postId}_1.jpg`), `picture ${SLICE2_MARKS.media}`); writeFileSync(path.join(dir, "shot.png"), `shot ${SLICE2_MARKS.shot}`); writeFileSync( path.join(dir, "capture.json"), JSON.stringify({ version: 1, id: o.postId, url: `https://x.com/i/status/${o.postId}`, capturedAt: "2026-11-18T10:05:00.000Z", state: "captured", shot: { name: "shot.png", bytes: 1, sha256: "0".repeat(64) }, mediaState: "ok", media: [{ name: `${o.postId}_1.jpg`, bytes: 1, sha256: "0".repeat(64), url: `https://pbs.twimg.com/media/${SLICE2_MARKS.address}.jpg` }], context: { readAt: "2026-11-18T10:05:00.000Z", quoted: { text: `quoted ${SLICE2_MARKS.context}`, media: [] } }, }), ); await adoptXTrendingMedia(libRoot, { postId: o.postId, name: `${o.postId}_1.jpg`, url: `https://pbs.twimg.com/media/${SLICE2_MARKS.address}.jpg` }); await ensureXTrendingMediaIgnore(libRoot); await writePostAvailability(trendingDir(libRoot), { [o.postId]: { availability: "available", checkedAt: "2026-11-18T10:05:00.000Z" } }); }