XORE21 commited on
Commit
a6bee49
·
verified ·
1 Parent(s): 0b3372a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +31 -16
index.js CHANGED
@@ -1,11 +1,9 @@
1
  const express = require('express');
2
  const cors = require('cors');
3
  const { connect } = require("puppeteer-real-browser");
4
-
5
  const puppeteer = require('puppeteer-extra');
6
  const StealthPlugin = require('puppeteer-extra-plugin-stealth');
7
 
8
- // Aktifkan Stealth
9
  puppeteer.use(StealthPlugin());
10
 
11
  const recaptchav3 = require('./endpoints/recaptchav3');
@@ -15,16 +13,20 @@ const port = process.env.PORT || 7860;
15
  app.use(cors());
16
  app.use(express.json());
17
 
18
- let activeBrowsers = 0;
 
19
 
20
  async function createBrowser() {
21
- // Kita gunakan connect dari puppeteer-real-browser tapi dengan settingan stealth
22
  const { browser, page } = await connect({
23
  headless: false,
24
  args: [
25
  '--no-sandbox',
26
  '--disable-setuid-sandbox',
27
- '--disable-blink-features=AutomationControlled', // Sembunyikan identitas bot
 
 
 
 
28
  '--window-size=1920,1080'
29
  ],
30
  connectOption: { defaultViewport: null }
@@ -34,11 +36,16 @@ async function createBrowser() {
34
 
35
  app.post('/recaptchav3', async (req, res) => {
36
  const { url, siteKey, action } = req.body;
37
-
38
- if (!url || !siteKey) return res.status(400).json({ status: "error", message: "Missing params" });
39
- if (activeBrowsers >= 5) return res.status(429).json({ status: "busy", message: "Server busy" });
40
 
41
- activeBrowsers++;
 
 
 
 
 
 
 
 
42
  let browserInstance = null;
43
 
44
  try {
@@ -46,17 +53,25 @@ app.post('/recaptchav3', async (req, res) => {
46
  browserInstance = browser;
47
 
48
  const token = await recaptchav3(page, url, siteKey, action || 'submit');
49
-
50
- res.json({ status: "success", token: token });
 
 
 
51
 
52
  } catch (error) {
53
- console.error("Handler Error:", error.message);
54
- res.status(500).json({ status: "error", message: error.message });
 
 
55
  } finally {
56
- if (browserInstance) try { await browserInstance.close(); } catch {}
57
- activeBrowsers--;
 
 
58
  }
59
  });
60
 
61
  app.get('/', (req, res) => res.send("RV3 Solver Ready"));
62
- app.listen(port, () => console.log(`Running on ${port}`));
 
 
1
  const express = require('express');
2
  const cors = require('cors');
3
  const { connect } = require("puppeteer-real-browser");
 
4
  const puppeteer = require('puppeteer-extra');
5
  const StealthPlugin = require('puppeteer-extra-plugin-stealth');
6
 
 
7
  puppeteer.use(StealthPlugin());
8
 
9
  const recaptchav3 = require('./endpoints/recaptchav3');
 
13
  app.use(cors());
14
  app.use(express.json());
15
 
16
+ const MAX_CONCURRENT = 5;
17
+ let active = 0;
18
 
19
  async function createBrowser() {
 
20
  const { browser, page } = await connect({
21
  headless: false,
22
  args: [
23
  '--no-sandbox',
24
  '--disable-setuid-sandbox',
25
+ '--disable-dev-shm-usage',
26
+ '--disable-accelerated-2d-canvas',
27
+ '--no-first-run',
28
+ '--no-zygote',
29
+ '--disable-gpu',
30
  '--window-size=1920,1080'
31
  ],
32
  connectOption: { defaultViewport: null }
 
36
 
37
  app.post('/recaptchav3', async (req, res) => {
38
  const { url, siteKey, action } = req.body;
 
 
 
39
 
40
+ if (!url || !siteKey) {
41
+ return res.status(400).json({ status: "error", message: "Missing url or siteKey" });
42
+ }
43
+
44
+ if (active >= MAX_CONCURRENT) {
45
+ return res.status(429).json({ status: "busy", message: "Server busy" });
46
+ }
47
+
48
+ active++;
49
  let browserInstance = null;
50
 
51
  try {
 
53
  browserInstance = browser;
54
 
55
  const token = await recaptchav3(page, url, siteKey, action || 'submit');
56
+
57
+ res.json({
58
+ status: "success",
59
+ token: token
60
+ });
61
 
62
  } catch (error) {
63
+ // TANGKAP ERROR DENGAN BENAR
64
+ const msg = error.message || String(error);
65
+ console.error("API Error:", msg);
66
+ res.status(500).json({ status: "error", message: msg });
67
  } finally {
68
+ if (browserInstance) {
69
+ try { await browserInstance.close(); } catch {}
70
+ }
71
+ active--;
72
  }
73
  });
74
 
75
  app.get('/', (req, res) => res.send("RV3 Solver Ready"));
76
+
77
+ app.listen(port, () => console.log(`Server running on ${port}`));