Nexchan commited on
Commit
49ebcc9
1 Parent(s): d126f19

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +57 -0
index.js CHANGED
@@ -251,6 +251,63 @@ app.get('/nhentai', async (req, res) => {
251
  }
252
  });
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  // Fungsi untuk ping website
255
  async function pingWebsite() {
256
  const browser = await puppeteer.launch({
 
251
  }
252
  });
253
 
254
+ async function r34(url) {
255
+ const browser = await puppeteer.launch({
256
+ headless: false, // Non-headless untuk debugging
257
+ args: ['--no-sandbox', '--disable-setuid-sandbox']
258
+ });
259
+
260
+ const page = await browser.newPage();
261
+
262
+ // Setel header User-Agent dan Referer
263
+ await page.setExtraHTTPHeaders({
264
+ 'User-Agent': getRandomUserAgent(),
265
+ 'Referer': url,
266
+ 'X-Forwarded-For': generateRandomIP()
267
+ });
268
+
269
+ // Setel direktori unduhan unik untuk setiap permintaan
270
+ const downloadPath = fs.mkdtempSync(path.join(os.tmpdir(), 'r34')); // Buat subdirektori unik
271
+
272
+ await page._client.send('Page.setDownloadBehavior', {
273
+ behavior: 'allow',
274
+ downloadPath: downloadPath
275
+ });
276
+
277
+ await page.goto(url); // Buka URL yang diberikan
278
+
279
+ // Asumsikan ada tombol unduh dengan selector '#downloadButton'
280
+ await page.click("#tab_video_info > div:nth-child(4) > div > a:nth-child(5)");
281
+
282
+ // Tunggu sampai file diunduh dengan memonitor perubahan pada direktori
283
+ let filename = '';
284
+ while (filename === '') {
285
+ const files = fs.readdirSync(downloadPath);
286
+ if (files.length > 0) {
287
+ filename = files[0]; // Ambil nama file pertama yang muncul
288
+ } else {
289
+ await new Promise(resolve => setTimeout(resolve, 100)); // Tunggu sebentar sebelum cek lagi
290
+ }
291
+ }
292
+
293
+ await browser.close();
294
+
295
+ return { path: path.join(downloadPath, filename), url: url };
296
+ }
297
+
298
+ app.get('/r34', async (req, res) => {
299
+ const { url } = req.query;
300
+ if (!url) {
301
+ return res.status(400).send('URL is required');
302
+ }
303
+ try {
304
+ const result = await r34(url);
305
+ res.json(result);
306
+ } catch (error) {
307
+ res.status(500).send('Error processing request');
308
+ }
309
+ });
310
+
311
  // Fungsi untuk ping website
312
  async function pingWebsite() {
313
  const browser = await puppeteer.launch({