Spaces:
Paused
Paused
Update Api.js
Browse files
Api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
/**
|
| 2 |
* API.js β FINAL TOTAL
|
| 3 |
-
* Rate limiting + Cloudflare Interstitial + Cache + Task Queue
|
| 4 |
*/
|
| 5 |
|
| 6 |
const express = require('express');
|
|
@@ -69,7 +69,7 @@ function writeCache(type, taskId, value) {
|
|
| 69 |
|
| 70 |
// ================= CLEAN CACHE PERIODIC =================
|
| 71 |
setInterval(() => {
|
| 72 |
-
const types = ["recaptcha2", "recaptcha3", "turnstile", "interstitial"];
|
| 73 |
const now = Date.now();
|
| 74 |
types.forEach(type => {
|
| 75 |
const dir = path.join(CACHE_DIR, type);
|
|
@@ -85,8 +85,8 @@ setInterval(() => {
|
|
| 85 |
}, 600000); // 10 menit
|
| 86 |
|
| 87 |
// ================= EXPRESS =================
|
| 88 |
-
app.use(express.json());
|
| 89 |
-
app.use(express.urlencoded({ extended: true }));
|
| 90 |
|
| 91 |
const tasks = {};
|
| 92 |
|
|
@@ -107,13 +107,14 @@ app.get("/", (req, res) => {
|
|
| 107 |
message: "CAPTCHA Solver API",
|
| 108 |
version: "8.0.0",
|
| 109 |
limits: { concurrent: MAX_CONCURRENT, timeout: global.timeOut },
|
| 110 |
-
endpoints: ["/solve", "/health", "/stats"]
|
| 111 |
});
|
| 112 |
});
|
| 113 |
|
| 114 |
// ================= SOLVE ENDPOINT =================
|
| 115 |
app.post('/solve', async (req, res) => {
|
| 116 |
-
|
|
|
|
| 117 |
|
| 118 |
// Polling jika taskId dikirim
|
| 119 |
if (taskId) {
|
|
@@ -132,7 +133,7 @@ app.post('/solve', async (req, res) => {
|
|
| 132 |
const cached = readCache(type, newTaskId);
|
| 133 |
if (cached) {
|
| 134 |
tasks[newTaskId] = cached;
|
| 135 |
-
return res.json({ taskId: newTaskId, status: "done", cached: true });
|
| 136 |
}
|
| 137 |
|
| 138 |
try {
|
|
@@ -150,7 +151,8 @@ app.post('/solve', async (req, res) => {
|
|
| 150 |
solution = await recaptchaV3({ domain, siteKey, action, proxy }, page);
|
| 151 |
break;
|
| 152 |
case "turnstile":
|
| 153 |
-
|
|
|
|
| 154 |
break;
|
| 155 |
case "interstitial":
|
| 156 |
solution = await interstitial({ domain, proxy }, page);
|
|
@@ -179,8 +181,7 @@ app.post('/solve', async (req, res) => {
|
|
| 179 |
res.status(500).json({ taskId: newTaskId, status: "error", message: error.message });
|
| 180 |
}
|
| 181 |
});
|
| 182 |
-
|
| 183 |
-
// GET /solve?taskId=xxx β polling
|
| 184 |
app.get('/solve', (req, res) => {
|
| 185 |
const { taskId } = req.query;
|
| 186 |
if (!taskId) return res.status(400).json({ error: "Missing taskId" });
|
|
@@ -190,6 +191,46 @@ app.get('/solve', (req, res) => {
|
|
| 190 |
return res.json({ status: task.status, solution: task.solution });
|
| 191 |
});
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
// ================= BROWSER INIT =================
|
| 194 |
async function init_browser(proxyServer = null) {
|
| 195 |
const connectOptions = {
|
|
@@ -230,7 +271,8 @@ async function init_browser(proxyServer = null) {
|
|
| 230 |
const recaptchaV2 = require('./Api/recaptcha2');
|
| 231 |
const recaptchaV3 = require('./Api/recaptcha3');
|
| 232 |
const turnstile = require('./Api/turnstile');
|
| 233 |
-
const interstitial = require('./interstitial');
|
|
|
|
| 234 |
|
| 235 |
// ================= STATS =================
|
| 236 |
app.get('/stats', (req, res) => {
|
|
@@ -257,4 +299,4 @@ app.listen(port, () => {
|
|
| 257 |
π Started: ${new Date().toISOString()}
|
| 258 |
==========================================
|
| 259 |
`);
|
| 260 |
-
});
|
|
|
|
| 1 |
/**
|
| 2 |
* API.js β FINAL TOTAL
|
| 3 |
+
* Rate limiting + Cloudflare Interstitial + Cache + Task Queue + Ablink
|
| 4 |
*/
|
| 5 |
|
| 6 |
const express = require('express');
|
|
|
|
| 69 |
|
| 70 |
// ================= CLEAN CACHE PERIODIC =================
|
| 71 |
setInterval(() => {
|
| 72 |
+
const types = ["recaptcha2", "recaptcha3", "turnstile", "interstitial", "ablink"];
|
| 73 |
const now = Date.now();
|
| 74 |
types.forEach(type => {
|
| 75 |
const dir = path.join(CACHE_DIR, type);
|
|
|
|
| 85 |
}, 600000); // 10 menit
|
| 86 |
|
| 87 |
// ================= EXPRESS =================
|
| 88 |
+
app.use(express.json({ limit: '10mb' }));
|
| 89 |
+
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
| 90 |
|
| 91 |
const tasks = {};
|
| 92 |
|
|
|
|
| 107 |
message: "CAPTCHA Solver API",
|
| 108 |
version: "8.0.0",
|
| 109 |
limits: { concurrent: MAX_CONCURRENT, timeout: global.timeOut },
|
| 110 |
+
endpoints: ["/solve", "/solve/ablink", "/health", "/stats"]
|
| 111 |
});
|
| 112 |
});
|
| 113 |
|
| 114 |
// ================= SOLVE ENDPOINT =================
|
| 115 |
app.post('/solve', async (req, res) => {
|
| 116 |
+
// Tambahkan cdata di sini
|
| 117 |
+
const { type, domain, siteKey, taskId, action, proxy, isInvisible, cdata } = req.body;
|
| 118 |
|
| 119 |
// Polling jika taskId dikirim
|
| 120 |
if (taskId) {
|
|
|
|
| 133 |
const cached = readCache(type, newTaskId);
|
| 134 |
if (cached) {
|
| 135 |
tasks[newTaskId] = cached;
|
| 136 |
+
return res.json({ taskId: newTaskId, status: "done", cached: true, solution: cached.solution });
|
| 137 |
}
|
| 138 |
|
| 139 |
try {
|
|
|
|
| 151 |
solution = await recaptchaV3({ domain, siteKey, action, proxy }, page);
|
| 152 |
break;
|
| 153 |
case "turnstile":
|
| 154 |
+
// Kirimkan cdata ke fungsi turnstile
|
| 155 |
+
solution = await turnstile({ domain, siteKey, action, cdata, proxy }, page);
|
| 156 |
break;
|
| 157 |
case "interstitial":
|
| 158 |
solution = await interstitial({ domain, proxy }, page);
|
|
|
|
| 181 |
res.status(500).json({ taskId: newTaskId, status: "error", message: error.message });
|
| 182 |
}
|
| 183 |
});
|
| 184 |
+
// GET /solve?taskId=xxx β polling (existing)
|
|
|
|
| 185 |
app.get('/solve', (req, res) => {
|
| 186 |
const { taskId } = req.query;
|
| 187 |
if (!taskId) return res.status(400).json({ error: "Missing taskId" });
|
|
|
|
| 191 |
return res.json({ status: task.status, solution: task.solution });
|
| 192 |
});
|
| 193 |
|
| 194 |
+
// ================= ABLINK ENDPOINT =================
|
| 195 |
+
app.post('/solve/ablink', async (req, res) => {
|
| 196 |
+
const { instructionImage, options } = req.body;
|
| 197 |
+
if (!instructionImage || !Array.isArray(options) || options.length === 0) {
|
| 198 |
+
return res.status(400).json({ error: 'Missing instructionImage or options array' });
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
const newTaskId = Date.now().toString(36) + Math.random().toString(36).substr(2);
|
| 202 |
+
tasks[newTaskId] = { status: "pending" };
|
| 203 |
+
console.log(`π New ablink task: ${newTaskId}`);
|
| 204 |
+
|
| 205 |
+
// Cek cache
|
| 206 |
+
const cached = readCache("ablink", newTaskId);
|
| 207 |
+
if (cached) {
|
| 208 |
+
tasks[newTaskId] = cached;
|
| 209 |
+
return res.json({ taskId: newTaskId, status: "done", cached: true, solution: cached.solution });
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
try {
|
| 213 |
+
const result = await addTask(async () => {
|
| 214 |
+
console.log(`π Processing ablink: ${newTaskId}`);
|
| 215 |
+
const solution = await solveAblink(instructionImage, options);
|
| 216 |
+
tasks[newTaskId] = { status: "done", solution };
|
| 217 |
+
writeCache("ablink", newTaskId, tasks[newTaskId]);
|
| 218 |
+
return solution;
|
| 219 |
+
});
|
| 220 |
+
|
| 221 |
+
res.json({
|
| 222 |
+
taskId: newTaskId,
|
| 223 |
+
status: "queued",
|
| 224 |
+
position: taskQueue.length,
|
| 225 |
+
estimatedWait: taskQueue.length * 30000
|
| 226 |
+
});
|
| 227 |
+
} catch (error) {
|
| 228 |
+
tasks[newTaskId] = { status: "error", message: error.message };
|
| 229 |
+
console.error(`β Failed ablink: ${newTaskId} - ${error.message}`);
|
| 230 |
+
res.status(500).json({ taskId: newTaskId, status: "error", message: error.message });
|
| 231 |
+
}
|
| 232 |
+
});
|
| 233 |
+
|
| 234 |
// ================= BROWSER INIT =================
|
| 235 |
async function init_browser(proxyServer = null) {
|
| 236 |
const connectOptions = {
|
|
|
|
| 271 |
const recaptchaV2 = require('./Api/recaptcha2');
|
| 272 |
const recaptchaV3 = require('./Api/recaptcha3');
|
| 273 |
const turnstile = require('./Api/turnstile');
|
| 274 |
+
const interstitial = require('./interstitial');
|
| 275 |
+
const solveAblink = require('./ablinksolver');
|
| 276 |
|
| 277 |
// ================= STATS =================
|
| 278 |
app.get('/stats', (req, res) => {
|
|
|
|
| 299 |
π Started: ${new Date().toISOString()}
|
| 300 |
==========================================
|
| 301 |
`);
|
| 302 |
+
});
|