File size: 1,392 Bytes
7c363b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const cheerio = require('cheerio');
const { basename, extname } = require('path');

async function mediafire(url) {
    const $ = cheerio.load(await (await fetch(url.trim())).text())
    const title = $("meta[property='og:title']").attr("content")?.trim() || "Unknown"
    const size = /Download\s*\(([\d.]+\s*[KMGT]?B)\)/i.exec($.html())?.[1] || "Unknown"
    const dl = $("a.popsok[href^='https://download']").attr("href")?.trim() || $("a.popsok:not([href^='javascript'])").attr("href")?.trim() || (() => { throw new Error("Download URL not found.") })()
    return { name: title, filename: basename(dl), type: extname(dl), size, download: dl, link: url.trim() }
}

const handler = async (req, res) => {
  try {
    const { url } = req.query;

    if (!url) {
      return res.status(400).json({
        success: false,
        error: 'Missing required parameter: url'
      });
    }

    const result = await mediafire(url);
    res.json({
      author: "Herza",
      success: true,
      data: result
  });

  } catch (error) {
    res.status(500).json({
      success: false,
      error: error.message
    });
  }
};

module.exports = {
  name: 'MediaFire DL',
  description: 'Download File From Mediafire',
  type: 'GET',
  routes: ['api/download/mediafire'],
  tags: ['downloader', 'tools', 'misc'],
  parameters: ['url', 'key'],
  enabled: true,
  main: ['Downloader'],
  handler
}