mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
refactor(domain): introduce FeedRepository as the single KV access layer
Centralise the KV key schema and all get/put access behind a FeedRepository class under src/domain/. Every feed/email/list/icon/websub/counter key was previously inlined across ~12 modules with two divergent storeEmail and addFeedToList implementations; the dead src/utils/storage.ts write path is removed and the email key convention unified on feed:<id>:<ts>. Behaviour-preserving: existing tests pass unchanged in logic, plus a new feed-repository.test.ts covering CRUD, key builders, list ops and counters. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+6
-14
@@ -1,8 +1,9 @@
|
||||
import { Context } from "hono";
|
||||
import { html, raw } from "hono/html";
|
||||
import { Env, FeedConfig, FeedMetadata, EmailData } from "../types";
|
||||
import { Env } from "../types";
|
||||
import { processEmailContent } from "../utils/html-processor";
|
||||
import { formatBytes } from "../utils/format";
|
||||
import { FeedRepository } from "../domain/feed-repository";
|
||||
|
||||
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
const feedId = c.req.param("feedId");
|
||||
@@ -12,17 +13,11 @@ export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
return new Response("Not Found", { status: 404 });
|
||||
}
|
||||
|
||||
const emailStorage = c.env.EMAIL_STORAGE;
|
||||
const repo = FeedRepository.from(c.env);
|
||||
|
||||
const [feedMetadata, feedConfig] = await Promise.all([
|
||||
emailStorage.get(
|
||||
`feed:${feedId}:metadata`,
|
||||
"json",
|
||||
) as Promise<FeedMetadata | null>,
|
||||
emailStorage.get(
|
||||
`feed:${feedId}:config`,
|
||||
"json",
|
||||
) as Promise<FeedConfig | null>,
|
||||
repo.getMetadata(feedId),
|
||||
repo.getConfig(feedId),
|
||||
]);
|
||||
if (!feedMetadata) {
|
||||
return new Response("Feed not found", { status: 404 });
|
||||
@@ -41,10 +36,7 @@ export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
||||
return new Response("Entry not found", { status: 404 });
|
||||
}
|
||||
|
||||
const emailData = (await emailStorage.get(
|
||||
metaEntry.key,
|
||||
"json",
|
||||
)) as EmailData | null;
|
||||
const emailData = await repo.getEmail(metaEntry.key);
|
||||
if (!emailData) {
|
||||
return new Response("Entry not found", { status: 404 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user