mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
06c436c36a
Move four DDD tensions on the Feed aggregate to ground: - #1 The aggregate now holds a domain FeedState (camelCase) instead of the snake_case FeedConfig DTO; infrastructure/feed-mapper.ts owns the FeedState<->FeedConfig/FeedListItem translation as the sole snake_case site outside the HTTP edge. - #3 Replace the edit() recomputeExpiry control flag with a Lifetime VO: passing a lifetime recomputes expiry, omitting it preserves the current one (the dashboard quick-edit path). - #4 Domain events carry their own feedId; dispatchFeedEvents centralizes the drain+dispatch in the application layer (no more manual pullEvents at call sites), keeping infra->application dependency direction intact. - #6 Rename FeedId.fromTrusted to FeedId.unchecked to make the absence of revalidation explicit. Adds Lifetime + feed-mapper round-trip tests. 353 tests green, tsc clean, wrangler dry-run OK. Docs (CLAUDE.md) synced. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { Context } from "hono";
|
|
import { Env } from "../types";
|
|
import { generateRssFeed } from "../infrastructure/feed-generator";
|
|
import { fetchFeedData } from "../application/feed-fetcher";
|
|
import { baseUrl, feedRssUrl } from "../infrastructure/urls";
|
|
import { isExpired } from "../domain/feed";
|
|
import { FeedId } from "../domain/value-objects/feed-id";
|
|
|
|
export async function handle(c: Context<{ Bindings: Env }>): Promise<Response> {
|
|
try {
|
|
const feedId = c.req.param("feedId");
|
|
if (!feedId) {
|
|
return new Response("Feed ID is required", { status: 400 });
|
|
}
|
|
|
|
const feedData = await fetchFeedData(FeedId.unchecked(feedId), c.env);
|
|
if (!feedData) {
|
|
return new Response("Feed not found", { status: 404 });
|
|
}
|
|
if (isExpired(feedData.feedConfig)) {
|
|
return new Response("Feed has expired", { status: 410 });
|
|
}
|
|
|
|
const base = baseUrl(c.env);
|
|
const selfUrl = new URL(c.req.url).origin + `/rss/${feedId}`;
|
|
const rssXml = generateRssFeed(
|
|
feedData.feedConfig,
|
|
feedData.emails,
|
|
base,
|
|
feedId,
|
|
selfUrl,
|
|
);
|
|
const linkHeader = [
|
|
`<${base}/hub>; rel="hub"`,
|
|
`<${feedRssUrl(feedId, c.env)}>; rel="self"`,
|
|
].join(", ");
|
|
|
|
return new Response(rssXml, {
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "application/rss+xml",
|
|
"Cache-Control": "max-age=1800",
|
|
Link: linkHeader,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error("Error generating RSS feed:", error);
|
|
return new Response("Internal Server Error", { status: 500 });
|
|
}
|
|
}
|