|
|
const express = require('express'); |
|
|
const cors = require('cors'); |
|
|
const { connect } = require("puppeteer-real-browser"); |
|
|
const puppeteer = require('puppeteer-extra'); |
|
|
const StealthPlugin = require('puppeteer-extra-plugin-stealth'); |
|
|
|
|
|
puppeteer.use(StealthPlugin()); |
|
|
|
|
|
const recaptchav3 = require('./endpoints/recaptchav3'); |
|
|
const app = express(); |
|
|
const port = process.env.PORT || 7860; |
|
|
|
|
|
app.use(cors()); |
|
|
app.use(express.json()); |
|
|
|
|
|
const MAX_CONCURRENT = 5; |
|
|
let active = 0; |
|
|
|
|
|
async function createBrowser() { |
|
|
const { browser, page } = await connect({ |
|
|
headless: false, |
|
|
args: [ |
|
|
'--no-sandbox', |
|
|
'--disable-setuid-sandbox', |
|
|
'--disable-dev-shm-usage', |
|
|
'--disable-accelerated-2d-canvas', |
|
|
'--no-first-run', |
|
|
'--no-zygote', |
|
|
'--disable-gpu', |
|
|
'--window-size=1920,1080' |
|
|
], |
|
|
connectOption: { defaultViewport: null } |
|
|
}); |
|
|
return { browser, page }; |
|
|
} |
|
|
|
|
|
app.post('/recaptchav3', async (req, res) => { |
|
|
const { url, siteKey, action } = req.body; |
|
|
|
|
|
if (!url || !siteKey) { |
|
|
return res.status(400).json({ status: "error", message: "Missing url or siteKey" }); |
|
|
} |
|
|
|
|
|
if (active >= MAX_CONCURRENT) { |
|
|
return res.status(429).json({ status: "busy", message: "Server busy" }); |
|
|
} |
|
|
|
|
|
active++; |
|
|
let browserInstance = null; |
|
|
|
|
|
try { |
|
|
const { browser, page } = await createBrowser(); |
|
|
browserInstance = browser; |
|
|
|
|
|
const token = await recaptchav3(page, url, siteKey, action || 'submit'); |
|
|
|
|
|
res.json({ |
|
|
status: "success", |
|
|
token: token |
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
const msg = error.message || String(error); |
|
|
console.error("API Error:", msg); |
|
|
res.status(500).json({ status: "error", message: msg }); |
|
|
} finally { |
|
|
if (browserInstance) { |
|
|
try { await browserInstance.close(); } catch {} |
|
|
} |
|
|
active--; |
|
|
} |
|
|
}); |
|
|
|
|
|
app.get('/', (req, res) => res.send("RV3 Solver Ready")); |
|
|
|
|
|
app.listen(port, () => console.log(`Server running on ${port}`)); |