mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-21 06:13:48 +00:00
9eba4c34c6
Emails are now trimmed from the oldest end when total serialised size exceeds FEED_MAX_SIZE_BYTES (default 512 KB). Each EmailMetadata entry stores its size so future trims are computed without re-reading KV. Adds FEED_MAX_SIZE_BYTES, PROXY_TRUSTED_IPS and PROXY_AUTH_SECRET to Env. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
88 lines
2.0 KiB
TypeScript
88 lines
2.0 KiB
TypeScript
// Global environment interface for Cloudflare Workers
|
|
export interface Env {
|
|
EMAIL_STORAGE: KVNamespace;
|
|
ADMIN_PASSWORD: string;
|
|
DOMAIN: string;
|
|
FEED_MAX_SIZE_BYTES?: string;
|
|
PROXY_TRUSTED_IPS?: string;
|
|
PROXY_AUTH_SECRET?: string;
|
|
}
|
|
|
|
// Email interface for stored emails
|
|
export interface EmailData {
|
|
subject: string;
|
|
from: string;
|
|
content: string;
|
|
receivedAt: number;
|
|
headers: Record<string, string>;
|
|
}
|
|
|
|
// Feed configuration interface
|
|
export interface FeedConfig {
|
|
title: string;
|
|
description?: string;
|
|
allowed_senders?: string[];
|
|
language: string;
|
|
site_url: string;
|
|
feed_url: string;
|
|
author?: string;
|
|
created_at: number;
|
|
updated_at?: number;
|
|
}
|
|
|
|
// Feed metadata interface
|
|
export interface FeedMetadata {
|
|
emails: EmailMetadata[];
|
|
}
|
|
|
|
// Email metadata interface (summary info for listing)
|
|
export interface EmailMetadata {
|
|
key: string;
|
|
subject: string;
|
|
receivedAt: number;
|
|
size?: number;
|
|
}
|
|
|
|
// Feed list interface
|
|
export interface FeedList {
|
|
feeds: FeedListItem[];
|
|
}
|
|
|
|
// Feed summary interface (for the global feed list)
|
|
export interface FeedListItem {
|
|
id: string;
|
|
title: string;
|
|
description?: string;
|
|
}
|
|
|
|
// Declare KVNamespace for TypeScript
|
|
declare global {
|
|
// This is not an ideal solution but works for our example
|
|
interface KVNamespace {
|
|
get(key: string, options?: { type: "text" }): Promise<string | null>;
|
|
get(key: string, options: { type: "json" }): Promise<any | null>;
|
|
get(
|
|
key: string,
|
|
options: { type: "arrayBuffer" },
|
|
): Promise<ArrayBuffer | null>;
|
|
get(
|
|
key: string,
|
|
options: { type: "stream" },
|
|
): Promise<ReadableStream | null>;
|
|
put(
|
|
key: string,
|
|
value: string | ArrayBuffer | ReadableStream | FormData,
|
|
): Promise<void>;
|
|
delete(key: string): Promise<void>;
|
|
list(options?: {
|
|
prefix?: string;
|
|
limit?: number;
|
|
cursor?: string;
|
|
}): Promise<{
|
|
keys: { name: string; expiration?: number }[];
|
|
list_complete: boolean;
|
|
cursor?: string;
|
|
}>;
|
|
}
|
|
}
|