Skip to content

Commit 5b5a5de

Browse files
committed
Sync from main repo
1 parent 410f725 commit 5b5a5de

File tree

11 files changed

+1110
-763
lines changed

11 files changed

+1110
-763
lines changed

src/cache.ts

Lines changed: 0 additions & 143 deletions
This file was deleted.

src/config.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import "dotenv/config";
2-
import { FeedConfig } from "./types.js";
32

43
// Environment variables validation
54
const REQUIRED_ENV_VARS = ["API_SECRET"];
@@ -46,49 +45,3 @@ export const API_SECRET = process.env.API_SECRET!;
4645
export const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS
4746
? process.env.ALLOWED_ORIGINS.split(",")
4847
: ["*"];
49-
50-
// Default feed ID - since we're focusing on a single feed
51-
export const DEFAULT_FEED_ID = "main";
52-
53-
// Default configuration
54-
const DEFAULT_CONFIG: FeedConfig = {
55-
id: DEFAULT_FEED_ID,
56-
title: "Default RSS Feed",
57-
description: "A feed of curated content",
58-
siteUrl: "https://example.com",
59-
copyright: "test",
60-
language: "en",
61-
maxItems: 100,
62-
image: "https://example.com/logo.png",
63-
author: { name: "Feed Author", email: "author@example.com" },
64-
};
65-
66-
let currentConfig: FeedConfig | null = null;
67-
68-
// Set feed configuration
69-
export function setFeedConfig(config: FeedConfig): void {
70-
config.id = DEFAULT_FEED_ID;
71-
72-
// Set default values for optional fields if not provided
73-
config.title = config.title || DEFAULT_CONFIG.title;
74-
config.description = config.description || DEFAULT_CONFIG.description;
75-
config.siteUrl = config.siteUrl || DEFAULT_CONFIG.siteUrl;
76-
77-
// Ensure maxItems is always a positive number
78-
config.maxItems =
79-
typeof config.maxItems === "number" && config.maxItems > 0
80-
? config.maxItems
81-
: DEFAULT_CONFIG.maxItems;
82-
83-
config.language = config.language || DEFAULT_CONFIG.language;
84-
85-
// Update the in-memory configuration
86-
currentConfig = config;
87-
console.log("Updated feed configuration");
88-
}
89-
90-
// Get the current feed configuration
91-
export const getFeedConfig = (): FeedConfig => {
92-
const config = currentConfig || DEFAULT_CONFIG;
93-
return JSON.parse(JSON.stringify(config)) as FeedConfig;
94-
};

src/errors.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export class RssServiceError extends Error {
2+
constructor(
3+
message: string,
4+
public readonly statusCode: number,
5+
) {
6+
super(message);
7+
this.name = this.constructor.name;
8+
}
9+
}
10+
11+
export class FeedNotFoundError extends RssServiceError {
12+
constructor(feedId: string) {
13+
super(`Feed with ID '${feedId}' not found.`, 404);
14+
}
15+
}
16+
17+
export class DuplicateItemError extends RssServiceError {
18+
constructor(guid: string) {
19+
super(`Item with GUID '${guid}' already exists in this feed.`, 409);
20+
}
21+
}
22+
23+
export class InvalidPayloadError extends RssServiceError {
24+
constructor(message: string) {
25+
super(message, 400);
26+
}
27+
}
28+
29+
export class FeedConfigurationError extends RssServiceError {
30+
constructor(message: string) {
31+
super(`Feed configuration error: ${message}`, 400);
32+
}
33+
}
34+
35+
export class StorageError extends RssServiceError {
36+
constructor(message: string) {
37+
super(`Storage error: ${message}`, 500);
38+
}
39+
}

src/formatters.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Feed, Item } from "feed";
2-
import { getFeedConfig } from "./config.js";
3-
import { ApiFormat, FeedFormat, RssItem } from "./types.js";
2+
import { ApiFormat, FeedFormat, RssItem, FeedConfig } from "./types.js";
43
import { stripHtml } from "./utils.js";
54

65
/**
@@ -71,9 +70,9 @@ export function formatItems(
7170
*/
7271
export function generateFeed(
7372
items: string[],
73+
feedConfig: FeedConfig,
7474
format: FeedFormat = "rss",
7575
): { content: string; contentType: string } {
76-
const feedConfig = getFeedConfig();
7776
// For raw format, return JSON with no HTML
7877
if (format === "raw") {
7978
const rawItems = formatItems(items, "raw");

0 commit comments

Comments
 (0)