diff --git a/src/config/constants.ts b/src/config/constants.ts new file mode 100644 index 0000000..21c7ddb --- /dev/null +++ b/src/config/constants.ts @@ -0,0 +1,23 @@ +/** Maximum total size of emails stored per feed (bytes). */ +export const FEED_MAX_BYTES = 524288; // 512 KB + +/** Cache TTL for ForwardEmail.net IP list (milliseconds). */ +export const FORWARD_EMAIL_IPS_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours + +/** Admin session cookie max-age (seconds). */ +export const ADMIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7; // 1 week + +/** Maximum number of feed items exposed in RSS/Atom responses. */ +export const MAX_FEED_ITEMS = 20; + +/** Maximum number of email entries kept in feed metadata. */ +export const MAX_METADATA_EMAILS = 50; + +/** Default WebSub lease duration (seconds). */ +export const DEFAULT_LEASE_SECONDS = 86400; // 24 hours + +/** Maximum WebSub lease duration (seconds). */ +export const MAX_LEASE_SECONDS = 30 * 24 * 3600; // 30 days + +/** KV key for the global feed list. */ +export const FEEDS_LIST_KEY = "feeds:list"; diff --git a/src/utils/feed-fetcher.ts b/src/utils/feed-fetcher.ts index 634b631..6e1c18f 100644 --- a/src/utils/feed-fetcher.ts +++ b/src/utils/feed-fetcher.ts @@ -1,6 +1,5 @@ import { Env, FeedConfig, FeedMetadata, EmailData } from "../types"; - -const MAX_FEED_ITEMS = 20; +import { MAX_FEED_ITEMS } from "../config/constants"; export interface FeedData { feedConfig: FeedConfig; diff --git a/src/utils/storage.ts b/src/utils/storage.ts index 06ef138..19d4611 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -5,6 +5,7 @@ import { FeedList, EmailMetadata, } from "../types"; +import { MAX_METADATA_EMAILS } from "../config/constants"; /** * Store email data in KV @@ -49,10 +50,13 @@ async function updateFeedMetadata( // Add new email to the beginning of the list metadata.emails.unshift(emailMetadata); - // Keep only the last 50 emails in the metadata; delete orphaned KV entries - const toDelete = metadata.emails.length > 50 ? metadata.emails.slice(50) : []; + // Keep only the last MAX_METADATA_EMAILS in the metadata; delete orphaned KV entries + const toDelete = + metadata.emails.length > MAX_METADATA_EMAILS + ? metadata.emails.slice(MAX_METADATA_EMAILS) + : []; if (toDelete.length > 0) { - metadata.emails = metadata.emails.slice(0, 50); + metadata.emails = metadata.emails.slice(0, MAX_METADATA_EMAILS); } await Promise.all([