FeedRepository no longer owns favicons, WebSub subscriber lists or the monitoring counters singleton. Each concern gets its own repository (IconRepository, WebSubSubscriptionRepository, CountersRepository), sharing the key schema via feed-keys. KV key strings are unchanged; counters increment policy stays in utils/stats.ts. Co-Authored-By: Claude Opus 4.7 <[email protected]>
32 lines
929 B
TypeScript
32 lines
929 B
TypeScript
import { Env } from "../types";
|
|
import { feedKeys } from "./feed-keys";
|
|
|
|
/**
|
|
* KV access for cached per-domain favicons (`icon:<domain>`). 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<string | null> {
|
|
return this.kv.get(feedKeys.icon(domain), "text");
|
|
}
|
|
|
|
async getJson<T>(domain: string): Promise<T | null> {
|
|
return (await this.kv.get(feedKeys.icon(domain), {
|
|
type: "json",
|
|
})) as T | null;
|
|
}
|
|
|
|
async put(domain: string, value: string, ttlSeconds: number): Promise<void> {
|
|
await this.kv.put(feedKeys.icon(domain), value, {
|
|
expirationTtl: ttlSeconds,
|
|
});
|
|
}
|
|
}
|