(sock, message, args, context)
| 25 | description: 'Download files from MediaFire', |
| 26 | usage: '.mediafire <url>', |
| 27 | async handler(sock, message, args, context) { |
| 28 | const { chatId } = context; |
| 29 | const text = args.join(' '); |
| 30 | if (!text) |
| 31 | return await sock.sendMessage(chatId, { text: "❌ Provide a MediaFire URL.\n\nExample:\n.mfire https://www.mediafire.com/file/5e54xv2cislhfgb/twoxzhn.zip/file" }, { quoted: message }); |
| 32 | try { |
| 33 | const data = await mediafireDl(text); |
| 34 | if (!data || !data.link) { |
| 35 | return await sock.sendMessage(chatId, { text: "❌ Failed to parse MediaFire page. Link might be private or broken." }, { quoted: message }); |
| 36 | } |
| 37 | let caption = `≡ *MEDIAFIRE DOWNLOADER*\n\n`; |
| 38 | caption += `▢ *File:* ${data.name}\n`; |
| 39 | caption += `▢ *Size:* ${data.size}\n`; |
| 40 | caption += `▢ *Extension:* ${data.ext}\n\n`; |
| 41 | caption += `*Download In Progress... Please Wait ⌛*`; |
| 42 | await sock.sendMessage(chatId, { text: caption }, { quoted: message }); |
| 43 | const response = await axios({ |
| 44 | method: 'get', |
| 45 | url: data.link, |
| 46 | responseType: 'arraybuffer', |
| 47 | headers: { |
| 48 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', |
| 49 | 'Referer': text |
| 50 | } |
| 51 | }); |
| 52 | const buffer = Buffer.from(response.data); |
| 53 | if (buffer.length < 10000) { |
| 54 | return await sock.sendMessage(chatId, { text: "❌ Error: The downloaded file is corrupt or invalid." }); |
| 55 | } |
| 56 | let mimeType = 'application/octet-stream'; |
| 57 | const mimes = { |
| 58 | 'zip': 'application/zip', |
| 59 | 'pdf': 'application/pdf', |
| 60 | 'apk': 'application/vnd.android.package-archive', |
| 61 | 'mp4': 'video/mp4', |
| 62 | 'mp3': 'audio/mpeg', |
| 63 | 'jpg': 'image/jpeg', |
| 64 | 'png': 'image/png' |
| 65 | }; |
| 66 | if (mimes[data.ext.toLowerCase()]) |
| 67 | mimeType = mimes[data.ext.toLowerCase()]; |
| 68 | await sock.sendMessage(chatId, { |
| 69 | document: buffer, |
| 70 | fileName: data.name, |
| 71 | mimetype: mimeType, |
| 72 | caption: `✅ *Download Complete:* ${data.name}` |
| 73 | }, { quoted: message }); |
| 74 | } |
| 75 | catch (err) { |
| 76 | console.error('MF Download Error:', err); |
| 77 | await sock.sendMessage(chatId, { text: `❌ Error: ${ err.message}` }, { quoted: message }); |
| 78 | } |
| 79 | } |
| 80 | }; |
nothing calls this directly
no test coverage detected