// A fake Wayback Machine on loopback (release 29 S0): the CDX search API and // capture pages, for the deleted-video fallback's lookup. No test reaches the // real web.archive.org. // // const wb = await startFakeWayback(); // wb.fetch a fetch that sends https://web.archive.org/… here // wb.base the loopback origin // wb.requests every request path, in order (pacing tests read the times in `at`) // await wb.close() // // Routes: // GET /cdx/search/cdx?url=[&output=json][&limit=N][&filter=statuscode:200][&matchType=…] // output=json: a header row ["urlkey","timestamp","original","mimetype","statuscode","digest","length"] // then one row per capture of (oldest first); no captures: `[]` (the real API's empty answer) // without output=json: the same rows space-separated, one per line // GET /web/[id_|if_]/ the capture (text/html), 404 for an unknown one // GET /__wb/videoinfo?vtype=youtube&vid= (release 29 review) what yt-dlp's // YoutubeWebArchive extractor asks: `{formats: [...]}` for an id in // opts.videos (default VIDEOS), `{}` for any other — the video itself // archived, not only its watch page // GET /web/id_/ (release 32 R8) a format's STREAM, as yt-dlp fetches it // (`/web/2id_/`): fake bytes (a Range is answered 206) when the format's `id` // is in opts.streams (default: opts.videos), 404 otherwise — an id in `videos` but // not in `streams` is the live case, the index listing a video Wayback does not hold // GET /web/[id_|if_]/ (release 37) a PAGE capture's body (PAGE_CAPTURES, // or opts.pageCaptures) with its own mimetype; a timestamp with no capture of a // known page answers 302 to the nearest one; a capture with `offsite` answers 302 there // opts.busyTimes: the first N CDX requests answer 429 (Retry-After: 1); opts.downTimes: then 503s. // ── THE SCAN LISTING (release 37 S2, lib/waybackPages/scanCdx.ts) ── // GET /cdx/search/cdx?…&showResumeKey=true the paged listing a Wayback pages scan asks: // matchType exact|prefix|host|domain, from/to (timestamp prefixes), every `filter=` // (`[!]field:regex`, a whole-field match, over statuscode and mimetype), collapse=digest // (adjacent rows of one URL with one digest listed once), fl (the columns, in order), // limit, and resumeKey — the answer ends with [] and [] when rows remain. // A capture's `digest` is its own when it names one, else DIGEST. // opts.scanRefuseFrom: the Nth scan request (1-based) and every one after answer 503. // opts.streamBusyTimes: the first N stream requests answer 429 (Retry-After: 1). // opts.excluded: (release 37 lane F) originals the archive answers 403 for — CDX and // their captures — while every other URL answers as usual. import http from "node:http"; const HEADER = ["urlkey", "timestamp", "original", "mimetype", "statuscode", "digest", "length"]; // Invented captures. `bread-day-01`'s watch page was captured twice (one a // redirect), `gone-video-05` once; anything else has none. export const CAPTURES = [ { original: "https://video.example/watch?v=bread-day-01", timestamp: "20260106120000", statuscode: "200", mimetype: "text/html" }, { original: "https://video.example/watch?v=bread-day-01", timestamp: "20260301080000", statuscode: "302", mimetype: "text/html" }, { original: "https://video.example/watch?v=gone-video-05", timestamp: "20260125093000", statuscode: "200", mimetype: "text/html" }, ]; const urlkey = (u) => { try { const x = new URL(u); return `${x.hostname.split(".").reverse().join(",")})${x.pathname}${x.search}`.toLowerCase(); } catch { return u; } }; // ─── Release 37 (lane A): page captures, served raw (`id_`) ─────────────── // // Invented pages. Each is a capture of a page that is not a video, with the // body the archive would answer `/web/id_/` with: // ARTICLE a blog post: nav, header, footer, aside around an
, // og:title, article:published_time, a rewritten link and images // TOOLBAR a page whose body still carries the Wayback toolbar insert, its // /_static/ + wombat scripts, and /web// rewritten hrefs // BIG a 3 MB page (over the 2 MB cap) // PLAIN a text/plain capture // IMAGE an image/jpeg capture (refused by its mimetype) // JUMP a capture that recorded a redirect OFF the archive // A timestamp the fake holds no capture of answers 302 to the nearest capture // of the same page (the archive's own behaviour); CDX lists every page capture // and honours `closest=` (nearest first). export const PAGE_ARTICLE_URL = "https://blog.example/2014/03/a-post.html"; export const PAGE_ARTICLE_TS = "20140305120000"; export const PAGE_ARTICLE_LATER_TS = "20150611090000"; export const PAGE_TOOLBAR_URL = "https://home.example/about"; export const PAGE_TOOLBAR_TS = "20150101000000"; export const PAGE_BIG_URL = "https://big.example/dump.html"; export const PAGE_BIG_TS = "20160101000000"; export const PAGE_PLAIN_URL = "https://notes.example/readme.txt"; export const PAGE_PLAIN_TS = "20180101000000"; export const PAGE_IMAGE_URL = "https://img.example/pic.jpg"; export const PAGE_IMAGE_TS = "20190101000000"; export const PAGE_JUMP_URL = "https://jump.example/"; export const PAGE_JUMP_TS = "20170101000000"; const articleHtml = (version) => ` A Post About Bread | Example Blog

Example Blog

A Post About Bread

The first loaf came out flat, and the second, and the third, which is how it goes when the starter is young.

A starter needs a week of feeding before it rises a loaf; see the starter post for the schedule.

Bake it until it sounds hollow.

  • Flour, 500 g
  • Water, 350 g
A flat loaf
  day 1: feed
  day 2: feed
${version > 1 ? "

Update: the fourth loaf rose.

" : ""}
Copyright 2014 Example Blog. About
`; const toolbarHtml = ` About Us

About us

We are a small group that makes zines about our town, and we have done so since 2009, every season.

Write to us through the contact page or see our links.

`; export const PAGE_CAPTURES = [ { original: PAGE_ARTICLE_URL, timestamp: PAGE_ARTICLE_TS, statuscode: "200", mimetype: "text/html", body: () => articleHtml(1) }, { original: PAGE_ARTICLE_URL, timestamp: PAGE_ARTICLE_LATER_TS, statuscode: "200", mimetype: "text/html", body: () => articleHtml(2) }, { original: PAGE_TOOLBAR_URL, timestamp: PAGE_TOOLBAR_TS, statuscode: "200", mimetype: "text/html", body: () => toolbarHtml }, { original: PAGE_BIG_URL, timestamp: PAGE_BIG_TS, statuscode: "200", mimetype: "text/html", body: () => `

${"word ".repeat(600 * 1024)}

`, }, { original: PAGE_PLAIN_URL, timestamp: PAGE_PLAIN_TS, statuscode: "200", mimetype: "text/plain", body: () => "README\n\nThe notes of a small project, kept as plain text.\n" }, { original: PAGE_IMAGE_URL, timestamp: PAGE_IMAGE_TS, statuscode: "200", mimetype: "image/jpeg", body: () => Buffer.alloc(2048, 1) }, { original: PAGE_JUMP_URL, timestamp: PAGE_JUMP_TS, statuscode: "302", mimetype: "text/html", offsite: "https://elsewhere.example/landing" }, ]; // ─── Release 37 (lane D): a capture that holds several items, and images ─── // // SPLIT a Tumblr-themed blog index (two posts, each a fixed-width box, the // second with an image) — split by the Tumblr extractor into // `tumblr-` records, each shot clipped to its own post // Served as every page capture is (`id_` / `if_` / framed). `/web/im_/` // of an image URL (.jpg/.jpeg/.png/.gif/.webp) answers a small PNG — the page // records' images through their own Wayback URLs; any other `im_` is a 404. export const PAGE_SPLIT_URL = "https://crumb-notes.tumblr.com/"; export const PAGE_SPLIT_TS = "20120601000000"; export const PAGE_SPLIT_POSTS = ["30000000002", "30000000001"]; // A 2×2 PNG (opaque grey). export const IMAGE_PNG = Buffer.from( "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAADklEQVR4nGNoAAMGCAUAKg4GARWeQtcAAAAASUVORK5CYII=", "base64", ); const splitHtml = ` Crumb Notes

On crusts

A crust should crackle when it cools on the rack.

On crumbs

An open crumb comes from a wet dough and a long, slow rise.

a sliced loaf
`; export const PAGE_CAPTURES_SPLIT = [ { original: PAGE_SPLIT_URL, timestamp: PAGE_SPLIT_TS, statuscode: "200", mimetype: "text/html", body: () => splitHtml }, ]; // The answer to `/web/[mod]/` for a page capture, or null when // the original is not one of PAGE_CAPTURES. function pageCaptureAnswer(pageCaptures, ts, mod, original, send, res) { const list = pageCaptures.filter((c) => c.original === original); if (list.length === 0) return false; const exact = list.find((c) => c.timestamp === ts); if (!exact) { const want = Number(ts.padEnd(14, "0")); const near = [...list].sort((a, b) => Math.abs(Number(a.timestamp) - want) - Math.abs(Number(b.timestamp) - want))[0]; res.writeHead(302, { location: `https://web.archive.org/web/${near.timestamp}${mod}/${near.original}`, "content-type": "text/html" }); res.end(""); return true; } if (exact.offsite) { res.writeHead(302, { location: exact.offsite, "content-type": "text/html" }); res.end(""); return true; } const body = exact.body(); const type = exact.mimetype === "text/html" || exact.mimetype === "text/plain" ? `${exact.mimetype}; charset=utf-8` : exact.mimetype; send(200, type, body); return true; } // ─── Release 37 (lane E): Save Page Now (SPN2) ────────────────────────────── // // POST /save url=&capture_outlinks=0, Authorization // `LOW :` → {url, job_id}; a wrong // or missing key → 401; opts.spn.busyTimes → 429 // (Retry-After: 1) first; a url in opts.spn.refuseUrls // → 200 {status: "error", status_ext: "error:blocked-url"} // GET /save/status/ {status: "pending"} for opts.spn.pendingPolls polls // (default 1), then {status: "success", timestamp, // original_url} — and the capture is served raw like a // page capture from then on (opts.spn.pages[url] or a // synthetic page) — or, for a url in opts.spn.failUrls, // {status: "error", status_ext: "error:not-found"} // The keys are FAKE_SPN_ACCESS / FAKE_SPN_SECRET; nothing real. export const FAKE_SPN_ACCESS = "FAKEACCESS0001"; export const FAKE_SPN_SECRET = "FAKESECRET0001"; export const SPN_CAPTURE_TS = "20261020120000"; const spnPageHtml = (url) => ` A page saved now

A page saved now

This synthetic page stands for ${url}, captured by the fake Save Page Now while it was still up.

It says what the page said on the day it was saved, which is the point of saving it.

Footer
`; function readBody(req) { return new Promise((resolve) => { const chunks = []; req.on("data", (c) => chunks.push(c)); req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8"))); }); } // The SPN routes; true when the request was one of them. function spnAnswer(spn, req, u, send) { if (u.pathname === "/save" && req.method === "POST") { void readBody(req).then((body) => { if (req.headers.authorization !== `LOW ${spn.access}:${spn.secret}`) { return send(401, "application/json", JSON.stringify({ message: "You need to be logged in to use Save Page Now." })); } if (spn.busy > 0) { spn.busy--; return send(429, "application/json", JSON.stringify({ message: "You have already reached the limit of active sessions." }), { "retry-after": "1" }); } const url = new URLSearchParams(body).get("url") ?? ""; spn.forms.push(Object.fromEntries(new URLSearchParams(body))); if (spn.refuseUrls.includes(url)) { return send(200, "application/json", JSON.stringify({ status: "error", status_ext: "error:blocked-url", message: "This URL is in the Save Page Now service block list." })); } const jobId = `spn2-fake-${++spn.seq}`; spn.jobs.set(jobId, { url, polls: 0 }); return send(200, "application/json", JSON.stringify({ url, job_id: jobId })); }); return true; } const st = /^\/save\/status\/([^/]+)$/.exec(u.pathname); if (st && req.method === "GET") { const job = spn.jobs.get(decodeURIComponent(st[1])); if (!job) { send(404, "application/json", JSON.stringify({ status: "error", message: "Job not found." })); return true; } job.polls++; if (job.polls <= spn.pendingPolls) { send(200, "application/json", JSON.stringify({ status: "pending", job_id: st[1] })); return true; } if (spn.failUrls.includes(job.url)) { send(200, "application/json", JSON.stringify({ status: "error", status_ext: "error:not-found", message: "Server returned a 404 for this page." })); return true; } if (!spn.captured.some((c) => c.original === job.url)) { const page = spn.pages[job.url]; spn.captured.push({ original: job.url, timestamp: spn.timestamp, statuscode: "200", mimetype: "text/html", body: () => page ?? spnPageHtml(job.url) }); } send(200, "application/json", JSON.stringify({ status: "success", job_id: st[1], timestamp: spn.timestamp, original_url: job.url, duration_sec: 3 })); return true; } return false; } // YouTube ids whose video (not only its page) the fake archive holds. export const VIDEOS = ["gone-video-05"]; export async function startFakeWayback(opts = {}) { // Release 37: the page captures are served beside whatever `captures` says, // and listed by CDX unless a test names its own `captures`. const pageCaptures = opts.pageCaptures ?? [...PAGE_CAPTURES, ...PAGE_CAPTURES_SPLIT]; const captures = opts.captures ?? [...CAPTURES, ...pageCaptures]; const videos = opts.videos ?? VIDEOS; const streams = opts.streams ?? videos; let streamBusy = opts.streamBusyTimes ?? 0; const requests = []; let busy = opts.busyTimes ?? 0; let down = opts.downTimes ?? 0; const excluded = opts.excluded ?? []; let scanRequests = 0; // Release 37 (lane E): Save Page Now's state. const spn = { access: opts.spn?.access ?? FAKE_SPN_ACCESS, secret: opts.spn?.secret ?? FAKE_SPN_SECRET, busy: opts.spn?.busyTimes ?? 0, pendingPolls: opts.spn?.pendingPolls ?? 1, failUrls: opts.spn?.failUrls ?? [], refuseUrls: opts.spn?.refuseUrls ?? [], pages: opts.spn?.pages ?? {}, timestamp: opts.spn?.timestamp ?? SPN_CAPTURE_TS, jobs: new Map(), seq: 0, forms: [], captured: [], }; const server = http.createServer((req, res) => { const u = new URL(req.url ?? "/", "http://fake"); requests.push({ path: u.pathname + u.search, at: Date.now(), method: req.method }); const send = (status, type, body, headers = {}) => { res.writeHead(status, { "content-type": type, ...headers }); res.end(body); }; // ─── Release 37 (lane F): an EXCLUDED URL — CDX and its captures answer // 403, as the Wayback Machine does for a URL it will not show anyone // (opts.excluded: the originals). Every other URL answers as usual. if (excluded.length > 0) { const asked = u.pathname === "/cdx/search/cdx" ? (u.searchParams.get("url") ?? "") : /^\/web\/\d{1,14}(?:[a-z]{2}_)?\/(.+)$/.exec(u.pathname + u.search)?.[1] ?? ""; if (asked && excluded.includes(asked)) { return send(403, "text/html", "

Sorry. This URL has been excluded from the Wayback Machine.

"); } } // Release 37 (lane E): Save Page Now, and the captures it made (raw). if (spnAnswer(spn, req, u, send)) return; const spc = /^\/web\/(\d{1,14})(id_|if_)?\/(.+)$/.exec(u.pathname + u.search); if (spc && pageCaptureAnswer(spn.captured, spc[1], spc[2] ?? "", spc[3], send, res)) return; if (u.pathname === "/cdx/search/cdx") { if (busy > 0) { busy--; return send(429, "text/plain", "Too Many Requests", { "retry-after": "1" }); } if (down > 0) { down--; return send(503, "text/plain", "Service Unavailable"); } if (u.searchParams.get("showResumeKey") === "true") { scanRequests++; if (opts.scanRefuseFrom && scanRequests >= opts.scanRefuseFrom) return send(503, "text/plain", "Service Unavailable"); return send(200, "application/json", JSON.stringify(scanListing(captures, u.searchParams))); } const want = u.searchParams.get("url") ?? ""; const prefix = u.searchParams.get("matchType") === "prefix"; const status = /^statuscode:(\d+)$/.exec(u.searchParams.get("filter") ?? "")?.[1]; const limit = Number(u.searchParams.get("limit") ?? 0) || Infinity; // Release 37: `closest=` (with sort=closest) lists the nearest first. const closest = u.searchParams.get("closest"); const near = (c) => Math.abs(Number(c.timestamp) - Number(String(closest).padEnd(14, "0"))); const rows = captures .filter((c) => (prefix ? c.original.startsWith(want) : c.original === want)) .filter((c) => !status || c.statuscode === status) .sort((a, b) => (closest ? near(a) - near(b) : 0) || a.timestamp.localeCompare(b.timestamp)) .slice(0, limit) .map((c) => [urlkey(c.original), c.timestamp, c.original, c.mimetype ?? "text/html", c.statuscode, c.digest ?? `DIGEST${c.timestamp}`, "1234"]); if (u.searchParams.get("output") === "json") return send(200, "application/json", JSON.stringify(rows.length ? [HEADER, ...rows] : [])); return send(200, "text/plain", rows.map((r) => r.join(" ")).join("\n") + (rows.length ? "\n" : "")); } if (u.pathname === "/__wb/videoinfo") { const vid = u.searchParams.get("vid") ?? ""; const body = videos.includes(vid) ? { formats: [{ url: `https://rr1---sn-fake.googlevideo.com/videoplayback?itag=18&id=${vid}`, ext: "mp4" }] } : {}; return send(200, "application/json", JSON.stringify(body)); } const st = /^\/web\/\d{1,14}id_\/(https?:\/\/[^/]*googlevideo\.com\/.+)$/.exec(u.pathname + u.search); if (st) { if (streamBusy > 0) { streamBusy--; return send(429, "text/plain", "Too Many Requests", { "retry-after": "1" }); } const id = new URL(st[1]).searchParams.get("id") ?? ""; if (!streams.includes(id)) return send(404, "text/html", "

Wayback Machine has not archived that URL.

"); const body = Buffer.alloc(4096, 7); const range = /^bytes=(\d+)-(\d*)$/.exec(String(req.headers.range ?? "")); if (!range) return send(200, "video/mp4", body); const from = Number(range[1]); const to = Math.min(body.length - 1, range[2] ? Number(range[2]) : body.length - 1); return send(206, "video/mp4", body.subarray(from, to + 1), { "content-range": `bytes ${from}-${to}/${body.length}` }); } // Release 37 (lane D): an archived image by its own Wayback URL. const im = /^\/web\/(\d{1,14})im_\/(.+)$/.exec(u.pathname + u.search); if (im) { if (/\.(?:jpe?g|png|gif|webp)$/i.test(im[2])) return send(200, "image/png", IMAGE_PNG); return send(404, "text/html", "

Wayback Machine has not archived that URL.

"); } // Release 37: a page capture (PAGE_CAPTURES), raw. const pc = /^\/web\/(\d{1,14})(id_|if_)?\/(.+)$/.exec(u.pathname + u.search); if (pc && pageCaptureAnswer(pageCaptures, pc[1], pc[2] ?? "", pc[3], send, res)) return; const m = /^\/web\/(\d{14})(?:id_|if_)?\/(.+)$/.exec(u.pathname + u.search); if (m) { const c = captures.find((x) => x.timestamp === m[1] && x.original === m[2]); if (!c) return send(404, "text/html", "

Wayback Machine has not archived that URL.

"); return send(200, "text/html; charset=utf-8", `capture ${c.timestamp}

${c.original}

`); } return send(404, "text/plain", "not found"); }); await new Promise((r) => server.listen(0, "127.0.0.1", r)); const base = `http://127.0.0.1:${server.address().port}`; return { base, requests, // Release 37 (lane E): the SPN forms posted (no headers), and the captures made. spnForms: spn.forms, spnCaptures: spn.captured, fetch: (url, init) => fetch(String(url).replace(/^https?:\/\/web\.archive\.org/, base), init), close: () => new Promise((r) => server.close(() => r())), }; } // ── THE SCAN LISTING (release 37 S2) ───────────────────────────────────────── // Its own block: the paged, filtered, collapsed listing a Wayback pages scan // asks for. Nothing above calls it unless the request carries showResumeKey. // Invented page captures for a scan: a blog on blog.example with posts across // 2014–2015 (one post captured three times, twice with the same content), its // stylesheet and a logo (assets), a 404, and an about page on a second host of // the same domain. export const SCAN_CAPTURES = [ { original: "https://blog.example/", timestamp: "20140102030405", statuscode: "200", mimetype: "text/html", digest: "HOMEA" }, { original: "https://blog.example/", timestamp: "20140601000000", statuscode: "200", mimetype: "text/html", digest: "HOMEA" }, { original: "https://blog.example/", timestamp: "20150101000000", statuscode: "200", mimetype: "text/html", digest: "HOMEB" }, { original: "https://blog.example/post/101/first-post", timestamp: "20140203000000", statuscode: "200", mimetype: "text/html", digest: "P101A" }, { original: "https://blog.example/post/101/first-post", timestamp: "20140304000000", statuscode: "200", mimetype: "text/html", digest: "P101A" }, { original: "https://blog.example/post/101/first-post", timestamp: "20150405000000", statuscode: "200", mimetype: "text/html", digest: "P101B" }, { original: "https://blog.example/post/102/second-post", timestamp: "20140506000000", statuscode: "200", mimetype: "text/html", digest: "P102A" }, { original: "https://blog.example/post/103/third-post", timestamp: "20150607000000", statuscode: "200", mimetype: "text/html", digest: "P103A" }, { original: "https://blog.example/tagged/bread", timestamp: "20150708000000", statuscode: "200", mimetype: "text/html", digest: "TAGA" }, { original: "https://blog.example/style.css", timestamp: "20140102030406", statuscode: "200", mimetype: "text/html", digest: "CSSA" }, { original: "https://blog.example/logo.png", timestamp: "20140102030407", statuscode: "200", mimetype: "image/png", digest: "PNGA" }, { original: "https://blog.example/post/999/gone", timestamp: "20150809000000", statuscode: "404", mimetype: "text/html", digest: "GONEA" }, { original: "https://about.blog.example/", timestamp: "20140910000000", statuscode: "200", mimetype: "text/html", digest: "ABOUTA" }, ]; const SCAN_FIELDS = ["urlkey", "timestamp", "original", "mimetype", "statuscode", "digest", "length"]; function hostOf(u) { try { return new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(u) ? u : `http://${u}`).hostname.toLowerCase(); } catch { return ""; } } const noScheme = (u) => u.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "").replace(/^www\./, ""); function matchesTarget(original, want, matchType) { if (matchType === "prefix") return noScheme(original).startsWith(noScheme(want)); if (matchType === "host") return hostOf(original).replace(/^www\./, "") === hostOf(want).replace(/^www\./, ""); if (matchType === "domain") { const h = hostOf(original); const d = hostOf(want).replace(/^www\./, ""); return h === d || h.endsWith(`.${d}`); } return noScheme(original) === noScheme(want); } export function scanListing(captures, q) { const want = q.get("url") ?? ""; const matchType = q.get("matchType") ?? "exact"; const from = (q.get("from") ?? "").padEnd(14, "0"); const to = (q.get("to") ?? "").padEnd(14, "9"); const filters = q.getAll("filter").map((f) => { const neg = f.startsWith("!"); const body = neg ? f.slice(1) : f; const i = body.indexOf(":"); return { neg, field: body.slice(0, i), re: new RegExp(`^(?:${body.slice(i + 1)})$`) }; }); const fl = (q.get("fl") ?? SCAN_FIELDS.join(",")).split(","); const limit = Number(q.get("limit") ?? 0) || Infinity; const offset = Number(/^fake-(\d+)$/.exec(q.get("resumeKey") ?? "")?.[1] ?? 0); const all = captures .map((c) => ({ urlkey: urlkey(c.original), timestamp: c.timestamp, original: c.original, mimetype: c.mimetype ?? "text/html", statuscode: c.statuscode, digest: c.digest ?? `DIGEST${c.timestamp}`, length: "1234", })) .filter((c) => matchesTarget(c.original, want, matchType)) .filter((c) => (!q.get("from") || c.timestamp >= from) && (!q.get("to") || c.timestamp <= to)) .filter((c) => filters.every((f) => f.re.test(String(c[f.field] ?? "")) !== f.neg)) .sort((a, b) => a.urlkey.localeCompare(b.urlkey) || a.timestamp.localeCompare(b.timestamp)); const collapsed = q.get("collapse") === "digest" ? all.filter((c, i) => i === 0 || !(all[i - 1].urlkey === c.urlkey && all[i - 1].digest === c.digest)) : all; const page = collapsed.slice(offset, offset + limit); const rows = page.map((c) => fl.map((f) => c[f] ?? "")); const more = offset + page.length < collapsed.length; if (rows.length === 0 && !more) return []; return [fl, ...rows, ...(more ? [[], [`fake-${offset + page.length}`]] : [])]; }