mirror of
https://github.com/juherr/kill-the-news.git
synced 2026-06-20 22:03:48 +00:00
feat(unsubscribe): RFC 8058 one-click unsubscribe on feed deletion
Capture each sender's List-Unsubscribe one-click URL during ingestion (stored per sender in feed metadata, mirroring the iconDomain pattern) and fire one-click POSTs via ctx.waitUntil when a feed is deleted, so newsletters stop mailing the now-dead address. Tracked with a new unsubscribes_sent counter surfaced on the status page and /api/stats. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { EmailData, FeedList, FeedListItem } from "../../types";
|
||||
import { EmailData, FeedList, FeedListItem, FeedMetadata } from "../../types";
|
||||
import { FEEDS_LIST_KEY } from "../../config/constants";
|
||||
import { logger } from "../../lib/logger";
|
||||
|
||||
@@ -132,6 +132,28 @@ export async function removeFeedFromList(
|
||||
return removed.includes(feedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a feed's stored RFC 8058 one-click unsubscribe URLs (one per sender).
|
||||
* Must be called before the feed metadata is deleted. Never throws.
|
||||
*/
|
||||
export async function collectUnsubscribeUrls(
|
||||
emailStorage: KVNamespace,
|
||||
feedId: string,
|
||||
): Promise<string[]> {
|
||||
try {
|
||||
const metadata = (await emailStorage.get(`feed:${feedId}:metadata`, {
|
||||
type: "json",
|
||||
})) as FeedMetadata | null;
|
||||
return Object.values(metadata?.unsubscribe ?? {});
|
||||
} catch (error) {
|
||||
logger.error("Error reading unsubscribe URLs", {
|
||||
feedId,
|
||||
error: String(error),
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function purgeFeedKeysStep(
|
||||
emailStorage: KVNamespace,
|
||||
feedId: string,
|
||||
|
||||
Reference in New Issue
Block a user