Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445import { get, set } from 'idb-keyval'
/** How long a saved scan is shown without re-reading the account. */export const SCAN_CACHE_TTL_MS = 15 * 60 * 1000
const PREFIX = 'threadbare:scan:v1:'
interface StoredScan<T> { savedAt: number result: T}
export interface CachedScan<T> { result: T savedAt: number fresh: boolean}
/** Read the saved scan for an account. Storage failures behave as a miss. */export async function readScan<T>( did: string, now = Date.now(),): Promise<CachedScan<T> | undefined> { try { const stored = await get<StoredScan<T>>(`${PREFIX}${did}`) if (!stored || typeof stored.savedAt !== 'number' || !stored.result) return undefined return { result: stored.result, savedAt: stored.savedAt, fresh: now - stored.savedAt >= 0 && now - stored.savedAt <= SCAN_CACHE_TTL_MS, } } catch { return undefined }}
/** Save a complete scan. Quota and private-mode failures are non-fatal. */export async function writeScan<T>(did: string, result: T): Promise<void> { try { await set(`${PREFIX}${did}`, { savedAt: Date.now(), result } satisfies StoredScan<T>) } catch { // The next visit simply re-reads the account. }}