mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
feat: extract constants module (P2-10)
Centralises magic numbers and string literals into src/config/constants.ts (FEED_MAX_BYTES, MAX_FEED_ITEMS, MAX_METADATA_EMAILS, ADMIN_COOKIE_MAX_AGE, FORWARD_EMAIL_IPS_CACHE_TTL_MS, DEFAULT_LEASE_SECONDS, MAX_LEASE_SECONDS, FEEDS_LIST_KEY). Consumers updated in storage.ts and feed-fetcher.ts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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";
|
||||
@@ -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;
|
||||
|
||||
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user