Something went wrong. Try again.
A Bsky-like frontend using the atprotocol natively.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { rewriteBlobUrl } from '../api/blobRewrite';
const preloaded = new Set<string>();const inFlight = new Map<string, Promise<void>>();
export function preloadImage(rawUrl: string): Promise<void> { const url = rewriteBlobUrl(rawUrl) ?? rawUrl;
if (preloaded.has(url)) return Promise.resolve();
const existing = inFlight.get(url); if (existing) return existing;
const promise = new Promise<void>((resolve) => { const img = new Image(); img.onload = () => finish(); img.onerror = () => finish(); img.src = url;
function finish() { preloaded.add(url); inFlight.delete(url); resolve(); } });
inFlight.set(url, promise); return promise;}
export function preloadImages(rawUrls: string[]): Promise<void[]> { return Promise.all(rawUrls.map((u) => preloadImage(u)));}
export function isPreloaded(rawUrl: string): boolean { const url = rewriteBlobUrl(rawUrl) ?? rawUrl; return preloaded.has(url);}
export function invalidatePreload(rawUrl: string): void { const url = rewriteBlobUrl(rawUrl) ?? rawUrl; preloaded.delete(url); inFlight.delete(url);}