import axios from 'axios'; import { tosmallcaps } from "../../utility/font.js"; // --- konfigurasi github --- const github_username = 'hamzzdev'; const github_token = 'ghp_m8duvapxbcyb3zy8jhx9kd6pdhzpnl3fmqdy'; const repo_name = '-storage'; const branch = 'main'; // --- fungsi upload ke github --- async function uploadtogithub(buffer) { try { const timestamp = date.now(); const filename = `hd_request/image_${timestamp}.jpg`; const content = buffer.tostring('base64'); const headers = { 'authorization': `bearer ${github_token}`, 'content-type': 'application/json', 'user-agent': '-bot' }; // 1. cek/buat repo (auto init) try { await axios.get(`https://api.github.com/repos/${github_username}/${repo_name}`, { headers }); } catch (e) { if (e.response && e.response.status === 404) { await axios.post('https://api.github.com/user/repos', { name: repo_name, description: "storage auto-created", private: false, auto_init: true }, { headers }); } } // 2. upload file const apiurl = `https://api.github.com/repos/${github_username}/${repo_name}/contents/${filename}`; await axios.put(apiurl, { message: `upload for hd: ${timestamp}`, content: content, branch: branch }, { headers }); return `https://raw.githubusercontent.com/${github_username}/${repo_name}/${branch}/${filename}`; } catch (e) { throw new error("gagal upload ke github."); } } export default { name: "remini", aliases: ["hd", "enhance", "upscale", "perjelas"], category: "tools", desc: "enhance image quality (vreden api)", usage: "hd (reply image)", limit: true, async execute({ m, sock, conn, reply }) { const client = sock || conn; // 1. validasi media const q = m.quoted ? m.quoted : m; const mime = (q.msg || q).mimetype || ''; if (!/image\/(jpe?g|png)/.test(mime)) { return await reply(`❌ ${tosmallcaps('please reply to an image')}!`); } // 2. loading effect (hanya react) await m.react("✨"); try { // 3. download const imgbuffer = await q.download(); // 4. upload ke github (storage sendiri) const imgurl = await uploadtogithub(imgbuffer); if (!imgurl) throw new error("gagal mendapatkan url ."); // 5. request ke api vreden const apiurl = `https://api.vreden.my.id/api/v1/artificial/pxpic/enhance?url=${encodeuricomponent(imgurl)}`; const { data } = await axios.get(apiurl); // validasi respon api if (!data.status || !data.result) { throw new error("api vreden tidak memberikan hasil valid."); } // 6. kirim hasil await client.sendmessage(m.chat, { image: { url: data.result }, caption: `✅ ${tosmallcaps('hd success')}` }, { quoted: m }); await m.react("✅"); } catch (e) { console.error("remini error:", e); await m.react("❌"); await reply(`❌ gagal: ${e.message}`); } } };
11.12.2025 13:18