// code from goatstore // api: https://store.agi.bd const axios = require("axios"); const fs = require("fs"); const path = require("path"); const FormData = require("form-data"); module.exports = { config: { name: "catbox", version: "1.0.1", author: "EryXenX", role: 0, shortDescription: "Upload file to Catbox", longDescription: "Upload replied attachment to Catbox", category: "media", guide: "{pn}" }, onStart: async function ({ api, event }) { const tid = event.threadID; const mid = event.messageID; const rep = event.messageReply; if (!rep || !rep.attachments || !rep.attachments.length) { return api.sendMessage( "❌ Reply to a file first.", tid, mid ); } const att = rep.attachments[0]; if (!att.url) { return api.sendMessage( "❌ File URL not found.", tid, mid ); } const dir = path.join(__dirname, "cache"); if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } const file = path.join( dir, "catbox_" + Date.now() + ".tmp" ); try { const res = await axios.get(att.url, { responseType: "arraybuffer", timeout: 120000, headers: { "User-Agent": "Mozilla/5.0" } }); fs.writeFileSync(file, res.data); const form = new FormData(); form.append("reqtype", "fileupload"); form.append( "fileToUpload", fs.createReadStream(file) ); const up = await axios.post( "https://catbox.moe/user/api.php", form, { headers: form.getHeaders(), timeout: 180000, maxBodyLength: Infinity, maxContentLength: Infinity } ); const url = String(up.data).trim(); if (!url.startsWith("http")) { throw new Error(url || "Catbox rejected the upload"); } return api.sendMessage( "✅ Catbox Upload Successful\n\n" + url, tid, mid ); } catch (err) { console.log("CATBOX ERROR:", err); return api.sendMessage( "❌ Catbox Upload Failed\n\n" + String(err.message || err), tid, mid ); } finally { if (fs.existsSync(file)) { try { fs.unlinkSync(file); } catch (e) {} } } } };