JerryCoderr

Untitled

Jun 20th, 2026 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Module } = require('../main');
  2. const axios = require('axios');
  3. const FormData = require('form-data');
  4. const fs = require('fs');
  5. const path = require('path');
  6. const config = require('../config');
  7.  
  8. const isFromMe = config.MODE === "public" ? false : true;
  9.  
  10. async function uploadToLitterbox(filePath) {
  11.     const form = new FormData();
  12.     form.append("reqtype", "fileupload");
  13.     form.append("time", "72h");
  14.     form.append("fileToUpload", fs.createReadStream(filePath), path.basename(filePath));
  15.  
  16.     const res = await axios.post(
  17.         "https://litterbox.catbox.moe/resources/internals/api.php",
  18.         form,
  19.         {
  20.             headers: {
  21.                 ...form.getHeaders()
  22.             },
  23.             maxBodyLength: Infinity,
  24.             maxContentLength: Infinity,
  25.             timeout: 60000
  26.         }
  27.     );
  28.  
  29.     if (!res.data || typeof res.data !== "string") {
  30.         throw new Error("Invalid response from Litterbox");
  31.     }
  32.  
  33.     return res.data.trim();
  34. }
  35.  
  36. async function uploadToARHosting(filePath) {
  37.     const form = new FormData();
  38.     form.append("file", fs.createReadStream(filePath), path.basename(filePath));
  39.  
  40.     const res = await axios.post(
  41.         "https://ar-hosting.pages.dev/upload",
  42.         form,
  43.         {
  44.             headers: {
  45.                 ...form.getHeaders()
  46.             },
  47.             maxBodyLength: Infinity,
  48.             maxContentLength: Infinity,
  49.             timeout: 60000
  50.         }
  51.     );
  52.  
  53.     if (!res.data || !(res.data.data || res.data.url)) {
  54.         throw new Error("Invalid response from AR Hosting");
  55.     }
  56.  
  57.     return res.data.data || res.data.url;
  58. }
  59.  
  60. Module({
  61.     pattern: "turl",
  62.     fromMe: isFromMe,
  63.     desc: "📤 Upload media to Litterbox (3 days)",
  64.     use: "utility",
  65.     usage: "turl (reply media)"
  66. }, async (message) => {
  67.  
  68.     const quoted = message.reply_message;
  69.     if (!quoted) {
  70.         return await message.sendReply("_Reply to any media file_");
  71.     }
  72.  
  73.     let tempMsg;
  74.     let filePath;
  75.  
  76.     try {
  77.         tempMsg = await message.sendReply("_Uploading (expires in 3 days) ⌛️..._");
  78.  
  79.         filePath = await quoted.download();
  80.  
  81.         const stats = fs.statSync(filePath);
  82.         const sizeMB = stats.size / (1024 * 1024);
  83.  
  84.         if (sizeMB > 200) {
  85.             throw new Error("File too large (Max ~200MB recommended)");
  86.         }
  87.  
  88.         let url;
  89. let host = "Litterbox";
  90.  
  91. try {
  92.     url = await uploadToLitterbox(filePath);
  93. } catch (err) {
  94.     const sizeMB = fs.statSync(filePath).size / (1024 * 1024);
  95.  
  96.     if (sizeMB > 20) {
  97.         throw new Error("Litterbox failed and AR Hosting only supports files up to 20MB.");
  98.     }
  99.  
  100.     url = await uploadToARHosting(filePath);
  101.     host = "AR Hosting";
  102. }
  103.  
  104.         await message.edit(
  105.     `_Upload successful ✅_
  106. _Host:_ ${host}
  107.  
  108. 🌐 ${url}`,
  109.     message.jid,
  110.     tempMsg.key
  111. );
  112.  
  113.     } catch (error) {
  114.         console.error("TURL Upload Error:", error.response?.data || error.message);
  115.  
  116.         await message.edit(
  117.             `_Upload failed ❌_\n${error.response?.data || error.message}`,
  118.             message.jid,
  119.             tempMsg?.key
  120.         );
  121.  
  122.     } finally {
  123.         if (filePath && fs.existsSync(filePath)) {
  124.             fs.unlinkSync(filePath);
  125.         }
  126.     }
  127. });
Add Comment
Please, Sign In to add comment