From 743b94d1a7800f68d12a3b73e3052ef2f2f6fed1 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Wed, 3 Dec 2025 17:15:10 -0800 Subject: [PATCH] Feat: Add unsubscribe API endpoint --- functions/api/unsubscribe.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 functions/api/unsubscribe.js diff --git a/functions/api/unsubscribe.js b/functions/api/unsubscribe.js new file mode 100644 index 0000000..3d6811b --- /dev/null +++ b/functions/api/unsubscribe.js @@ -0,0 +1,13 @@ +export async function onRequestPost({ request, env }) { + const { email } = await request.json().catch(() => ({})); + if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) + return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } }); + + await fetch(`https://ntfy.sh/${env.NTFY_TOPIC}`, { + method: 'POST', + headers: { Priority: '3', Title: `🔕 Unsubscribe` }, + body: email + }); + + return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } }); +}