mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 00:27:55 +00:00
Refactor: Replace ntfy.sh with Resend API for contact creation
This commit is contained in:
@@ -3,14 +3,19 @@ export async function onRequestPost({ request, env }) {
|
|||||||
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
|
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
|
||||||
return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } });
|
return new Response('{"error":"Invalid email"}', { status: 400, headers: { 'Content-Type': 'application/json' } });
|
||||||
|
|
||||||
const c = request.cf || {};
|
const res = await fetch('https://api.resend.com/contacts', {
|
||||||
const geo = [c.city, c.region, c.country].filter(Boolean).join(', ') || 'Unknown';
|
|
||||||
|
|
||||||
await fetch(`https://ntfy.sh/${env.NTFY_TOPIC}`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { Priority: '3', Title: `📬 ${geo}` },
|
headers: {
|
||||||
body: email
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${env.RESEND_KEY}`
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ email })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const text = await res.text();
|
||||||
|
return new Response(`{"error":"Resend error: ${text}"}`, { status: 500, headers: { 'Content-Type': 'application/json' } });
|
||||||
|
}
|
||||||
|
|
||||||
return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } });
|
return new Response('{"ok":true}', { headers: { 'Content-Type': 'application/json' } });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user