Nexchan commited on
Commit
d71e069
·
verified ·
1 Parent(s): 884d63b

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +81 -0
index.js CHANGED
@@ -283,6 +283,63 @@ function generateRandomID(length = 8) {
283
  return result;
284
  }
285
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  async function komiku_download(url) {
287
  const instanceID = generateRandomID();
288
  const tempDir = path.join(tempDirBase, instanceID);
@@ -400,6 +457,30 @@ app.get('/komiku/download', async (req, res) => {
400
  }
401
  });
402
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  /***********/
404
 
405
  async function getLatestKomik(page) {
 
283
  return result;
284
  }
285
 
286
+ async function Shinigami_download(url) {
287
+ const instanceID = generateRandomID();
288
+ const tempDir = `./${instanceID}`;
289
+ await fss.mkdir(tempDir);
290
+
291
+ // Extracting the title from the URL
292
+ const title = url.replace(/.*\/([^\/]+)\/([^\/]+)\/$/, "$1_$2");
293
+
294
+ const browser = await puppeteer.launch({
295
+ headless: true,
296
+ args: ['--no-sandbox', '--disable-setuid-sandbox']
297
+ });
298
+ const page = await browser.newPage();
299
+
300
+ // Enable request interception to add custom headers
301
+ await page.setRequestInterception(true);
302
+ page.on('request', request => {
303
+ request.continue({
304
+ headers: {
305
+ ...request.headers(),
306
+ 'User-Agent': 'Mozilla/5.0 (Linux; Android 11; M2004J19C Build/RP1A.200720.011) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.129 Mobile Safari/537.36 WhatsApp/1.2.3',
307
+ 'Referer': 'https://shinigami03.com/',
308
+ 'Accept-Language': 'en-US,en;q=0.9',
309
+ 'Accept-Encoding': 'gzip, deflate, br'
310
+ }
311
+ });
312
+ });
313
+
314
+ await page.goto(url, { waitUntil: 'networkidle2' });
315
+
316
+ try {
317
+ const imgList = await page.evaluate(() => {
318
+ const elements = document.querySelectorAll("body > div.wrap > div > div > div > div > div > div > div > div > div.c-blog-post > div.entry-content > div > div > div.reading-content > div");
319
+ let data = [];
320
+ elements.forEach(element => {
321
+ const img = element.querySelector('span > img');
322
+ if (img) {
323
+ data.push({ path: img.src });
324
+ }
325
+ });
326
+ return data;
327
+ });
328
+
329
+ const imagePaths = await downloadImages(imgList, tempDir, instanceID);
330
+ const pdfPath = await createPDF(imagePaths, instanceID, tempDir);
331
+
332
+ console.log(`PDF berhasil dibuat: ${pdfPath}`);
333
+ return { path: pdfPath, title: title, url: `https://${process.env.SPACE_HOST}/temp/${path.basename(pdfPathq)}` };
334
+ } catch (error) {
335
+ console.error(error);
336
+ throw error;
337
+ } finally {
338
+ await browser.close();
339
+ await fss.rmdir(tempDir, { recursive: true });
340
+ }
341
+ }
342
+
343
  async function komiku_download(url) {
344
  const instanceID = generateRandomID();
345
  const tempDir = path.join(tempDirBase, instanceID);
 
457
  }
458
  });
459
 
460
+ app.get('/shinigami/download', async (req, res) => {
461
+ try {
462
+ const { url } = req.query;
463
+ if (!url) return res.status(400).json({ error: 'Parameter url is required' });
464
+
465
+ let result = await Shinigami_download(url);
466
+ res.json(result);
467
+
468
+ // Menghapus file setelah 10 menit
469
+ try {
470
+ await new Promise(resolve => setTimeout(resolve, 10 * 60 * 1000)); // 10 minutes
471
+ await fss.unlink(result.path);
472
+ console.log(`File ${result.path} deleted.`);
473
+ } catch (error) {
474
+ console.error(`Error deleting file ${result.path}:`, error);
475
+ }
476
+ } catch (error) {
477
+ console.error('Error processing request:', error);
478
+ res.status(500).json({
479
+ error: 'Failed to process request\n' + error
480
+ });
481
+ }
482
+ });
483
+
484
  /***********/
485
 
486
  async function getLatestKomik(page) {