import { Env } from "../types"; import { feedKeys } from "../domain/feed-keys"; /** * KV access for cached per-domain favicons (`icon:`). Entries may be * positive (base64 bytes) or negative (a sentinel marking a failed fetch), and * always carry a TTL — the cache's sole expiry mechanism. */ export class IconRepository { constructor(private readonly kv: KVNamespace) {} static from(env: Env): IconRepository { return new IconRepository(env.EMAIL_STORAGE); } getText(domain: string): Promise { return this.kv.get(feedKeys.icon(domain), "text"); } async getJson(domain: string): Promise { return (await this.kv.get(feedKeys.icon(domain), { type: "json", })) as T | null; } async put(domain: string, value: string, ttlSeconds: number): Promise { await this.kv.put(feedKeys.icon(domain), value, { expirationTtl: ttlSeconds, }); } }