// ONE PACING STATE FOR A PLATFORM'S STORED-URL FILES (release 32 R9). // // Odysee's CDN allows one new original file per rest (measured 2026-10-16: the // next file a minute later answered 429). Release 32 R7 spaced full downloads // from the stored media URL by STORED_URL_NEW_FILE_GAP_MS under the platformGap // key `stored-url:`; the clip cut kept only the clip gap // (`clip-window:`, 30 s), so a cut and a download minutes apart were // two new files inside one rest. Now both read the SAME state: // // - a full download always waits out the gap (it is a whole file); // - a clip cut waits it out unless the last stored-URL read on the platform // was the SAME file (two windows of one video are one file, already // unlocked by its page open) — a cut of a new file waits like a download; // - both note the gap at their start and their end, and remember the file. // // In memory and process-wide (on globalThis, as platformGap.ts is): a restart // is itself a gap. import { notePlatformGap, platformGapRemainingMs } from "./platformGap"; import { storedUrlGapKey } from "../lib/storedMediaUrl"; declare global { // eslint-disable-next-line no-var var __yttStoredUrlLastFile__: Map | undefined; } function lastFiles(): Map { if (!globalThis.__yttStoredUrlLastFile__) globalThis.__yttStoredUrlLastFile__ = new Map(); return globalThis.__yttStoredUrlLastFile__; } // The URL of the last stored-URL file read on `platform` in this process. export function storedUrlLastFile(platform: string): string | null { return lastFiles().get(storedUrlGapKey(platform)) ?? null; } // Milliseconds before a stored-URL read of `url` on `platform` may start. // `sameFileFree`: a read of the file read last owes no gap (the clip cut). export function storedUrlGapRemainingMs( platform: string, opts: { url?: string; sameFileFree?: boolean } = {}, now: number = Date.now(), ): number { if (opts.sameFileFree && opts.url && storedUrlLastFile(platform) === opts.url) return 0; return platformGapRemainingMs(storedUrlGapKey(platform), now); } // A stored-URL read of `url` on `platform` started or ended at `now`: the next // new file waits `gapMs` from now (never shortened), and this is the last file. export function noteStoredUrlRead( platform: string, url: string, gapMs: number, now: number = Date.now(), ): void { notePlatformGap(storedUrlGapKey(platform), gapMs, now); lastFiles().set(storedUrlGapKey(platform), url); } // Tests only. export function clearStoredUrlFiles(): void { lastFiles().clear(); }