File size: 2,128 Bytes
9f2381d
 
 
bdaf1b2
 
 
 
 
 
9f2381d
 
 
 
 
 
a6bee49
 
9f2381d
 
 
 
 
 
 
a6bee49
 
 
 
 
9f2381d
 
 
 
 
 
 
 
 
 
a6bee49
 
 
 
 
 
 
 
 
9f2381d
 
 
 
 
 
 
a6bee49
 
 
 
 
9f2381d
 
a6bee49
 
 
 
9f2381d
a6bee49
 
 
 
9f2381d
 
 
bdaf1b2
a6bee49
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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) {
        // TANGKAP ERROR DENGAN BENAR
        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}`));