import fetch from 'node-fetch'; const SOLVER_URL = 'https://gi2h-xxx.hf.space/solve'; const SOLVER_KEY = '00000000000000000000#0000000000000000000#000000000000000000#'; export async function getRecaptchaToken(domain, siteKey) { console.log('[solver] 🧩 Meminta token...'); console.log(`[solver] URL: ${SOLVER_URL}`); console.log(`[solver] Key: ${SOLVER_KEY.substring(0, 10)}...`); try { const submitRes = await fetch(SOLVER_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'key': SOLVER_KEY }, body: JSON.stringify({ type: 'recaptcha3', domain, siteKey }) }); if (!submitRes.ok) { throw new Error(`HTTP ${submitRes.status}: ${await submitRes.text()}`); } const submitData = await submitRes.json(); const taskId = submitData.taskId; if (!taskId) throw new Error('Gagal mendapatkan taskId'); console.log(`[solver] Task ID: ${taskId}`); for (let i = 0; i < 30; i++) { await new Promise(r => setTimeout(r, 2000)); const pollRes = await fetch(SOLVER_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'key': SOLVER_KEY }, body: JSON.stringify({ taskId }) }); const pollData = await pollRes.json(); if (pollData.status === 'done') { const token = pollData.token || pollData.solution?.token; console.log('[solver] ✅ Token diterima'); return token; } if (pollData.status === 'error') { throw new Error(`Solver error: ${pollData.message || 'unknown'}`); } } throw new Error('Timeout: solver tidak merespon'); } catch (e) { console.error('[solver] ❌ Gagal:', e.message); throw e; } }