/** * Short-lived, single-use store for content shared into Freezmo from another * app (the Web Share Target POST). Lives in memory only, expires after ten * minutes and is deleted on first read — nothing is written to disk. */ export type SharedFile = { name: string; type: string; data: string }; export type SharedPayload = { title?: string; text?: string; url?: string; files: SharedFile[]; expires: number; }; type Store = Map; const globalStore = globalThis as typeof globalThis & { __freezmoShareStore?: Store }; const store: Store = (globalStore.__freezmoShareStore ??= new Map()); const TTL_MS = 10 * 60 * 1000; export const MAX_SHARE_BYTES = 30 * 1024 * 1024; function prune(): void { const now = Date.now(); for (const [id, payload] of store) { if (payload.expires < now) store.delete(id); } } export function putShare(id: string, payload: Omit): void { prune(); store.set(id, { ...payload, expires: Date.now() + TTL_MS }); } export function takeShare(id: string): SharedPayload | null { prune(); const payload = store.get(id); if (!payload) return null; store.delete(id); return payload; }