Skip to content

Commit

Permalink
[ Jessi-md 4.8.4 ⏱️ ]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweeshachamodx authored Jan 28, 2024
1 parent e346a5e commit 6abfebe
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions plugins/downloader-mega.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { File } from "megajs";
import path from "path";

let handler = async (m, { conn, args, usedPrefix, text, command }) => {
try {
if (!text) return m.reply(`${usedPrefix + command} <url>`);

const file = File.fromURL(text);
await file.loadAttributes();

if (file.size >= 300000000) return m.reply('Error: File size is too large (Maximum Size: 300MB)');

const downloadingMessage = `> Downloading file... Please wait.`;
m.reply(downloadingMessage);
m.react('🌩')

const caption = `> Successfully downloaded\nFile: ${file.name}\nSize: ${formatBytes(file.size)}`;

const data = await file.downloadBuffer();

const fileExtension = path.extname(file.name).toLowerCase();
const mimeTypes = {
".mp4": "video/mp4",
".pdf": "application/pdf",
".zip": "application/zip",
".rar": "application/x-rar-compressed",
".7z": "application/x-7z-compressed",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
};

let mimetype = mimeTypes[fileExtension] || "application/octet-stream";

await conn.sendFile(m.chat, data, file.name, caption, m, null, { mimetype, asDocument: true });
await m.react('✅');

} catch (error) {
return m.react('❌');
return m.reply(`Error: ${error.message}`);

}
}

handler.help = ["mega"]
handler.tags = ["downloader"]
handler.command = /^(mega)$/i
export default handler

function formatBytes(bytes) {
if (bytes === 0) return '0 Bytes';

const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));

return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}

0 comments on commit 6abfebe

Please sign in to comment.