Upload 3 files
Browse files- Dockerfile (1).txt +15 -0
- api (1).js +126 -0
- package (1).json +13 -0
Dockerfile (1).txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20
|
| 2 |
+
|
| 3 |
+
# Install dependensi sistem keur Chrome & Sharp
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
libgbm-dev libnss3 libasound2 libxss1 libxtst6 \
|
| 6 |
+
libgl1-mesa-glx libglib2.0-0 tesseract-ocr \
|
| 7 |
+
--no-install-recommends && rm -rf /var/lib/apt/lists/*
|
| 8 |
+
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
COPY package*.json ./
|
| 11 |
+
RUN npm install
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
ENV PORT=7860
|
| 15 |
+
CMD ["node", "api.js"]
|
api (1).js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const puppeteer = require('puppeteer-extra');
|
| 3 |
+
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
| 4 |
+
const Tesseract = require('tesseract.js');
|
| 5 |
+
const sharp = require('sharp');
|
| 6 |
+
const crypto = require('crypto');
|
| 7 |
+
|
| 8 |
+
puppeteer.use(StealthPlugin());
|
| 9 |
+
|
| 10 |
+
const app = express();
|
| 11 |
+
const port = process.env.PORT || 7860;
|
| 12 |
+
|
| 13 |
+
// Fungsi pikeun nyieun sidik jari gambar (Hashing)
|
| 14 |
+
async function getImageHash(buffer) {
|
| 15 |
+
try {
|
| 16 |
+
const processed = await sharp(buffer)
|
| 17 |
+
.grayscale()
|
| 18 |
+
.resize(32, 32, { fit: 'fill' })
|
| 19 |
+
.threshold(120)
|
| 20 |
+
.toBuffer();
|
| 21 |
+
return crypto.createHash('md5').update(processed).digest('hex');
|
| 22 |
+
} catch (e) {
|
| 23 |
+
return null;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// Fungsi Pre-processing khusus OCR
|
| 28 |
+
async function preprocessForOCR(buffer) {
|
| 29 |
+
return await sharp(buffer)
|
| 30 |
+
.grayscale()
|
| 31 |
+
.threshold(120)
|
| 32 |
+
.resize(400) // Gedean meh leuwih jelas dibaca
|
| 33 |
+
.toBuffer();
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
app.get('/solve', async (req, res) => {
|
| 37 |
+
const targetUrl = req.query.url;
|
| 38 |
+
if (!targetUrl) return res.status(400).send({ error: "URL-na mana?" });
|
| 39 |
+
|
| 40 |
+
// ARGUMEN PENTING: Meh Hugging Face teu 503/Crash
|
| 41 |
+
const browser = await puppeteer.launch({
|
| 42 |
+
headless: "new",
|
| 43 |
+
args: [
|
| 44 |
+
'--no-sandbox',
|
| 45 |
+
'--disable-setuid-sandbox',
|
| 46 |
+
'--disable-dev-shm-usage',
|
| 47 |
+
'--disable-gpu',
|
| 48 |
+
'--no-zygote',
|
| 49 |
+
'--single-process',
|
| 50 |
+
'--hide-scrollbars'
|
| 51 |
+
]
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
try {
|
| 55 |
+
const page = await browser.newPage();
|
| 56 |
+
await page.setViewport({ width: 1280, height: 800 });
|
| 57 |
+
|
| 58 |
+
console.log(`Maju ka: ${targetUrl}`);
|
| 59 |
+
await page.goto(targetUrl, { waitUntil: 'networkidle2', timeout: 60000 });
|
| 60 |
+
|
| 61 |
+
// Tunggu antibot links aya dina DOM
|
| 62 |
+
await page.waitForSelector('.antibotlinks', { timeout: 15000 });
|
| 63 |
+
|
| 64 |
+
// 1. Baca Instruksi Utama
|
| 65 |
+
const instructionImg = await page.$('#atb-instruction img');
|
| 66 |
+
let instrBuffer = await instructionImg.screenshot();
|
| 67 |
+
instrBuffer = await preprocessForOCR(instrBuffer);
|
| 68 |
+
|
| 69 |
+
const { data: { text: rawInstruction } } = await Tesseract.recognize(instrBuffer, 'eng');
|
| 70 |
+
const order = rawInstruction.toLowerCase()
|
| 71 |
+
.replace(/[^a-z0-9, ]/g, '')
|
| 72 |
+
.split(/[, ]+/)
|
| 73 |
+
.filter(t => t.length > 0);
|
| 74 |
+
|
| 75 |
+
console.log("Urutan nu dideteksi:", order);
|
| 76 |
+
|
| 77 |
+
// 2. Scan & Map kabeh link antibot
|
| 78 |
+
const links = await page.$$('.antibotlinks a');
|
| 79 |
+
let linkMap = [];
|
| 80 |
+
|
| 81 |
+
for (const link of links) {
|
| 82 |
+
const img = await link.$('img');
|
| 83 |
+
const imgBuffer = await img.screenshot();
|
| 84 |
+
|
| 85 |
+
const cleanImg = await preprocessForOCR(imgBuffer);
|
| 86 |
+
const { data: { text: label } } = await Tesseract.recognize(cleanImg, 'eng');
|
| 87 |
+
|
| 88 |
+
linkMap.push({
|
| 89 |
+
element: link,
|
| 90 |
+
label: label.toLowerCase().replace(/[^a-z0-9]/g, ''),
|
| 91 |
+
done: false
|
| 92 |
+
});
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// 3. Eksekusi Klik dumasar urutan
|
| 96 |
+
let clickedItems = [];
|
| 97 |
+
for (const target of order) {
|
| 98 |
+
const match = linkMap.find(item =>
|
| 99 |
+
(item.label.includes(target) || target.includes(item.label)) && !item.done
|
| 100 |
+
);
|
| 101 |
+
|
| 102 |
+
if (match) {
|
| 103 |
+
console.log(`KLIK: ${match.label} (Target: ${target})`);
|
| 104 |
+
await match.element.click();
|
| 105 |
+
match.done = true;
|
| 106 |
+
clickedItems.push(target);
|
| 107 |
+
await new Promise(r => setTimeout(r, 1500));
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
res.send({
|
| 112 |
+
status: clickedItems.length === order.length ? "Success" : "Partial",
|
| 113 |
+
order: order,
|
| 114 |
+
clicked: clickedItems
|
| 115 |
+
});
|
| 116 |
+
|
| 117 |
+
} catch (err) {
|
| 118 |
+
console.error("Fatal Error:", err.message);
|
| 119 |
+
res.status(500).send({ error: err.message });
|
| 120 |
+
} finally {
|
| 121 |
+
// IEU PENTING: Meh RAM teu bocor sarta teu 503
|
| 122 |
+
await browser.close();
|
| 123 |
+
}
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
app.listen(port, () => console.log(`DAN Solver Engine up on port ${port}`));
|
package (1).json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Forget",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"main": "api.js",
|
| 5 |
+
"dependencies": {
|
| 6 |
+
"express": "^4.19.2",
|
| 7 |
+
"puppeteer": "^24.0.0",
|
| 8 |
+
"puppeteer-extra": "^3.3.6",
|
| 9 |
+
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
| 10 |
+
"tesseract.js": "^5.1.0",
|
| 11 |
+
"sharp": "^0.33.3"
|
| 12 |
+
}
|
| 13 |
+
}
|