Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Module } = require('../main');
- const axios = require('axios');
- const FormData = require('form-data');
- const fs = require('fs');
- const path = require('path');
- const config = require('../config');
- const isFromMe = config.MODE === "public" ? false : true;
- async function uploadToLitterbox(filePath) {
- const form = new FormData();
- form.append("reqtype", "fileupload");
- form.append("time", "72h");
- form.append("fileToUpload", fs.createReadStream(filePath), path.basename(filePath));
- const res = await axios.post(
- "https://litterbox.catbox.moe/resources/internals/api.php",
- form,
- {
- headers: {
- ...form.getHeaders()
- },
- maxBodyLength: Infinity,
- maxContentLength: Infinity,
- timeout: 60000
- }
- );
- if (!res.data || typeof res.data !== "string") {
- throw new Error("Invalid response from Litterbox");
- }
- return res.data.trim();
- }
- async function uploadToARHosting(filePath) {
- const form = new FormData();
- form.append("file", fs.createReadStream(filePath), path.basename(filePath));
- const res = await axios.post(
- "https://ar-hosting.pages.dev/upload",
- form,
- {
- headers: {
- ...form.getHeaders()
- },
- maxBodyLength: Infinity,
- maxContentLength: Infinity,
- timeout: 60000
- }
- );
- if (!res.data || !(res.data.data || res.data.url)) {
- throw new Error("Invalid response from AR Hosting");
- }
- return res.data.data || res.data.url;
- }
- Module({
- pattern: "turl",
- fromMe: isFromMe,
- desc: "📤 Upload media to Litterbox (3 days)",
- use: "utility",
- usage: "turl (reply media)"
- }, async (message) => {
- const quoted = message.reply_message;
- if (!quoted) {
- return await message.sendReply("_Reply to any media file_");
- }
- let tempMsg;
- let filePath;
- try {
- tempMsg = await message.sendReply("_Uploading (expires in 3 days) ⌛️..._");
- filePath = await quoted.download();
- const stats = fs.statSync(filePath);
- const sizeMB = stats.size / (1024 * 1024);
- if (sizeMB > 200) {
- throw new Error("File too large (Max ~200MB recommended)");
- }
- let url;
- let host = "Litterbox";
- try {
- url = await uploadToLitterbox(filePath);
- } catch (err) {
- const sizeMB = fs.statSync(filePath).size / (1024 * 1024);
- if (sizeMB > 20) {
- throw new Error("Litterbox failed and AR Hosting only supports files up to 20MB.");
- }
- url = await uploadToARHosting(filePath);
- host = "AR Hosting";
- }
- await message.edit(
- `_Upload successful ✅_
- _Host:_ ${host}
- 🌐 ${url}`,
- message.jid,
- tempMsg.key
- );
- } catch (error) {
- console.error("TURL Upload Error:", error.response?.data || error.message);
- await message.edit(
- `_Upload failed ❌_\n${error.response?.data || error.message}`,
- message.jid,
- tempMsg?.key
- );
- } finally {
- if (filePath && fs.existsSync(filePath)) {
- fs.unlinkSync(filePath);
- }
- }
- });
Add Comment
Please, Sign In to add comment