// A cited archive.org record carries its provenance into compose, and the // links a citation of it shows are derived from that (lib/archiveOrg.ts // archiveOrgCitationLinks): YouTube at the second for a mirror, the // archive.org page and the torrent as downloads. Every name here is invented. // // Run with: node_modules/.bin/tsx --test publish/composeReportsArchiveOrg.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { readCitedRecord } from "./composeReports"; import { archiveOrgCitationLinks, buildArchiveOrgProvenance } from "../lib/archiveOrg"; import { archiveOrgDetailsUrl, archiveOrgVideoId } from "../lib/archiveOrgId"; const ITEM = "example-item"; const FILE = "First Upload-AbC123xyz_9.mp4"; test("readCitedRecord loads an archive.org record's provenance; others get null", async () => { const channels = mkdtempSync(path.join(tmpdir(), "compose-archiveorg-")); const id = archiveOrgVideoId({ identifier: ITEM, file: FILE }); const dir = path.join(channels, "demo-archive", "data", id); mkdirSync(dir, { recursive: true }); writeFileSync( path.join(dir, "metadata.info.json"), JSON.stringify({ id: `${ITEM}/${FILE}`, extractor_key: "ArchiveOrg", title: "First Upload (original)", upload_date: "20230405", webpage_url: archiveOrgDetailsUrl({ identifier: ITEM, file: FILE }), }), ); const prov = buildArchiveOrgProvenance({ ref: { identifier: ITEM, file: FILE }, item: { metadata: { identifier: ITEM, title: "Example Archive" }, files: [{ name: FILE, source: "original" }, { name: `${ITEM}_archive.torrent`, source: "metadata" }], }, infoJson: { id: "AbC123xyz_9", extractor_key: "Youtube", upload_date: "20230405" }, fetchedAt: "2026-01-01T00:00:00.000Z", }); writeFileSync(path.join(dir, "archiveorg.json"), JSON.stringify(prov)); const rec = await readCitedRecord(channels, "demo-archive", id); assert.ok(rec); assert.equal(rec.summary.platform, "archiveorg"); assert.equal(rec.summary.id, id); assert.deepEqual(rec.archiveOrg, prov); const links = archiveOrgCitationLinks({ webpageUrl: rec.summary.webpageUrl, provenance: rec.archiveOrg, seconds: 12 }); assert.equal(links.original?.label, "YouTube"); assert.equal(links.original?.url, "https://www.youtube.com/watch?v=AbC123xyz_9&t=12s"); assert.deepEqual(links.downloads.map((d) => d.label), ["archive.org", "torrent"]); const yt = path.join(channels, "demo-archive", "data", "AbC123xyz_9"); mkdirSync(yt, { recursive: true }); writeFileSync(path.join(yt, "metadata.info.json"), JSON.stringify({ id: "AbC123xyz_9", extractor_key: "Youtube" })); assert.equal((await readCitedRecord(channels, "demo-archive", "AbC123xyz_9"))?.archiveOrg, null); });