| 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 | |
| } |