// settings.archives — the archive sources a page import reads (release 37 // lane F). Pure: the type, its defaults, the sanitizer settingsSchema.ts runs // it through and the per-field docs SETTINGS.md renders. import type { FieldDocs } from "../fieldDocs"; import { archiveTodayHostOf, DEFAULT_ARCHIVE_TODAY_HOST } from "./mementos"; export type ArchivesSettings = { archiveTodayHost: string; archiveTodayGapSeconds: number; archiveTodayCooldownMinutes: number; archiveTodayBrowser: boolean; }; export const DEFAULT_ARCHIVES_SETTINGS: ArchivesSettings = { archiveTodayHost: DEFAULT_ARCHIVE_TODAY_HOST, archiveTodayGapSeconds: 8, archiveTodayCooldownMinutes: 30, archiveTodayBrowser: true, }; export const ARCHIVES_SETTINGS_FIELD_DOCS: FieldDocs = { archiveTodayHost: "The archive.today name every request goes to (archive.ph, archive.today, archive.is, archive.li, archive.vn, " + "archive.fo or archive.md — one service). A copy's URL on any of them is read from this one. Anything else " + "falls back to archive.ph.", archiveTodayGapSeconds: "The least time between two archive.today requests, seconds, from the end of one to the start of the next, " + "with up to a quarter more at random. One request at a time, always. Clamped to [4, 120]; default 8.", archiveTodayCooldownMinutes: "After archive.today answers HTTP 429 (too many requests) the run stops, and no request goes to it for this " + "long (or its Retry-After, when longer). Clamped to [5, 1440]; default 30.", archiveTodayBrowser: "When archive.today answers with a check (a CAPTCHA, a browser check) instead of a copy, read the copy once " + "more through the headless browser on the archive session's profile (Connect archive session keeps a cleared " + "check there). Nothing is ever solved by code: a check the browser cannot pass is refused with a sentence. " + "False = refuse at the check.", }; const clamp = (v: unknown, d: number, min: number, max: number): number => { const n = typeof v === "number" && Number.isFinite(v) ? v : d; return Math.min(max, Math.max(min, n)); }; export function sanitizeArchives(value: unknown): ArchivesSettings { const r = (value && typeof value === "object" && !Array.isArray(value) ? value : {}) as Record; const d = DEFAULT_ARCHIVES_SETTINGS; return { archiveTodayHost: archiveTodayHostOf(r.archiveTodayHost), archiveTodayGapSeconds: clamp(r.archiveTodayGapSeconds, d.archiveTodayGapSeconds, 4, 120), archiveTodayCooldownMinutes: Math.round(clamp(r.archiveTodayCooldownMinutes, d.archiveTodayCooldownMinutes, 5, 1440)), archiveTodayBrowser: r.archiveTodayBrowser !== false, }; }