From b61f092ec12ac07caafbc9784b5bb5f56209ec04 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 24 Nov 2025 14:20:27 -0800 Subject: [PATCH] Refactor: Use emoji in notification title --- functions/api/subscribe.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/functions/api/subscribe.js b/functions/api/subscribe.js index d0df433..71e553e 100644 --- a/functions/api/subscribe.js +++ b/functions/api/subscribe.js @@ -1,15 +1,16 @@ -export async function onRequestPost(ctx) { - const { request, env } = ctx; +export async function onRequestPost({ request, env }) { const { email } = await request.json().catch(() => ({})); - if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { - return new Response(JSON.stringify({ error: 'Invalid email' }), { status: 400, headers: { 'Content-Type': 'application/json' } }); - } - const cf = request.cf || {}; - const geo = [cf.city, cf.region, cf.country].filter(Boolean).join(', ') || 'Unknown'; + if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) + return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } }); + + const c = request.cf || {}; + const geo = [c.city, c.region, c.country].filter(Boolean).join(', ') || 'Unknown'; + await fetch(`https://ntfy.sh/${env.NTFY_TOPIC}`, { method: 'POST', - headers: { Priority: '3', Title: `New sub: ${geo}` }, + headers: { Priority: '3', Title: `📬 ${geo}` }, body: email }); - return new Response(JSON.stringify({ ok: true }), { headers: { 'Content-Type': 'application/json' } }); + + return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } }); }