descargas-drive.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import fetch from 'node-fetch';
  2. const userCaptions = new Map();
  3. const userRequests = {};
  4. let handler = async (m, { conn, args, usedPrefix, command }) => {
  5. if (!args[0]) throw `⚠️ ${await tr("Ingrese una Url de Drive")}\n• ${await tr("Ejemplo")}: ${usedPrefix + command} https://drive.google.com/file/d/Kantu`;
  6. if (userRequests[m.sender]) {
  7. conn.reply(m.chat, `⏳ *${await tr("Hey")} @${m.sender.split('@')[0]}* ${await tr("*Espera...* Ya hay una solicitud en proceso. Por favor, espera a que termine antes de hacer otra...")}`, userCaptions.get(m.sender) || m)
  8. return;
  9. }
  10. userRequests[m.sender] = true;
  11. m.react("📥");
  12. try {
  13. const waitMessageSent = conn.reply(m.chat, `*⌛ ${await tr("Calma")} 🫡 ${await tr("clack, Ya estoy enviado el archivo")} 🚀*\n*${await tr("Si no le llega el archivo es debido a que es muy pesado")}*`, m)
  14. userCaptions.set(m.sender, waitMessageSent);
  15. const downloadAttempts = [
  16. async () => {
  17. const api = await fetch(`https://api.siputzx.my.id/api/d/gdrive?url=${args[0]}`);
  18. const data = await api.json();
  19. return { url: data.data.download,
  20. filename: data.data.name,
  21. };
  22. },
  23. async () => {
  24. const api = await fetch(`https://apis.davidcyriltech.my.id/gdrive?url=${args[0]}`);
  25. const data = await api.json();
  26. return { url: data.download_link,
  27. filename: data.name,
  28. }},
  29. ];
  30. let fileData = null;
  31. for (const attempt of downloadAttempts) {
  32. try {
  33. fileData = await attempt();
  34. if (fileData) break; // Si se obtiene un resultado, salir del bucle
  35. } catch (err) {
  36. console.error(`Error in attempt: ${err.message}`);
  37. continue; // Si falla, intentar con la siguiente API
  38. }}
  39. if (!fileData) {
  40. throw new Error(await tr('No se pudo descargar el archivo desde ninguna API'));
  41. }
  42. const { url, filename } = fileData;
  43. const mimetype = getMimetype(filename);
  44. await conn.sendMessage(m.chat, { document: { url: url }, mimetype: mimetype, fileName: filename, caption: null }, { quoted: m });
  45. await m.react("✅");
  46. } catch (e) {
  47. m.react(`❌`);
  48. m.reply(`\`\`\`⚠️ ${await tr("OCURRIO UN ERROR")} ⚠️\`\`\`\n\n> *${await tr("Reporta el siguiente error a mi creador con el comando:")}* #report\n\n>>> ${e} <<<< `)
  49. console.log(e);
  50. } finally {
  51. delete userRequests[m.sender];
  52. }
  53. };
  54. handler.help = ['drive'].map(v => v + ' <url>');
  55. handler.tags = ['downloader'];
  56. handler.command = /^(drive|drivedl|dldrive|gdrive)$/i;
  57. handler.register = true;
  58. handler.limit = 3;
  59. export default handler;
  60. const getMimetype = (fileName) => {
  61. const extension = fileName.split('.').pop().toLowerCase();
  62. const mimeTypes = {
  63. 'pdf': 'application/pdf',
  64. 'mp4': 'video/mp4',
  65. 'jpg': 'image/jpeg',
  66. 'jpeg': 'image/jpeg',
  67. 'png': 'image/png',
  68. 'zip': 'application/zip',
  69. 'doc': 'application/msword',
  70. 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  71. 'xls': 'application/vnd.ms-excel',
  72. 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  73. 'ppt': 'application/vnd.ms-powerpoint',
  74. 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  75. 'txt': 'text/plain',
  76. 'mp3': 'audio/mpeg',
  77. 'apk': 'application/vnd.android.package-archive',
  78. 'rar': 'application/x-rar-compressed',
  79. '7z': 'application/x-7z-compressed',
  80. 'mkv': 'video/x-matroska',
  81. 'avi': 'video/x-msvideo',
  82. 'mov': 'video/quicktime',
  83. 'wmv': 'video/x-ms-wmv',
  84. 'flv': 'video/x-flv',
  85. 'gif': 'image/gif',
  86. 'webp': 'image/webp',
  87. 'ogg': 'audio/ogg',
  88. 'wav': 'audio/wav',
  89. };
  90. return mimeTypes[extension] || 'application/octet-stream'; // Tipo por defecto
  91. };