Kembali ke Beranda
Gistify Snippet
Feb 20·1 file(s)
Public
Uploaded by Joy MD - Bot | 20/2/2026, 11.06.36
synced from github gist Vercel Deployment
#api
Vercel Deploymentplaintext
107 baris| 1 | /* |
| 2 | * ─────────────────────────── |
| 3 | * 🟢 JOY MD - SOURCE CODE |
| 4 | * ─────────────────────────── |
| 5 | * 👤 Channel : https://shorturl.at/ce5eX |
| 6 | * 📅 Fetched : 20/2/2026, 10.59.12 |
| 7 | * 📂 File : deploy_vercel_v2.js |
| 8 | * ─────────────────────────── |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | • Feature : deploy vercel v2 |
| 13 | • Credits : https://whatsapp.com/channel/0029Vb4fjWE1yT25R7epR110 |
| 14 | • doksli : alip/lippwangsaf own nefusoft |
| 15 | • Adapted for Joy-MD by Har (Converted to use adm-zip & axios) |
| 16 | */ |
| 17 | |
| 18 | import AdmZip from 'adm-zip'; |
| 19 | import axios from 'axios'; |
| 20 | |
| 21 | const getVercelToken = () => process.env.VERCEL_TOKEN || global.vercelToken || '' |
| 22 | |
| 23 | let handler = async (m, { conn, text, usedPrefix, command }) => { |
| 24 | if (!text) throw `Contoh: ${usedPrefix + command} <nama_web>`; |
| 25 | |
| 26 | const token = getVercelToken() |
| 27 | if (!token) return m.reply(`❌ Token Vercel belum diset. Gunakan .setvercel <token>`) |
| 28 | |
| 29 | const webName = text.trim().toLowerCase().replace(/[^a-z0-9-_]/g, ''); |
| 30 | const domainCheckUrl = `https://${webName}.vercel.app`; |
| 31 | |
| 32 | try { |
| 33 | const check = await axios.get(domainCheckUrl).catch(e => e.response); |
| 34 | if (check && check.status === 200) return m.reply(`❌ Nama web *${webName}* sudah digunakan. Silakan gunakan nama lain.`); |
| 35 | } catch (e) {} |
| 36 | |
| 37 | const quotedFile = m.quoted ? m.quoted : m; |
| 38 | const mime = (quotedFile.msg || quotedFile).mimetype || quotedFile.mediaType || ''; |
| 39 | |
| 40 | const filesToUpload = []; |
| 41 | if (/zip/.test(mime) || mime.includes('application/zip')) { |
| 42 | m.reply('⏳ Sedang memproses file ZIP, mohon tunggu...'); |
| 43 | const zipBuffer = await quotedFile.download(); |
| 44 | |
| 45 | const zip = new AdmZip(zipBuffer); |
| 46 | const zipEntries = zip.getEntries(); |
| 47 | |
| 48 | for (const entry of zipEntries) { |
| 49 | if (!entry.isDirectory) { |
| 50 | const content = entry.getData() |
| 51 | const filePath = entry.entryName.replace(/^\/+/, '').replace(/\\/g, '/'); |
| 52 | filesToUpload.push({ |
| 53 | file: filePath, |
| 54 | data: content.toString('base64'), |
| 55 | encoding: 'base64' |
| 56 | }); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (!filesToUpload.some(x => x.file.toLowerCase().endsWith('index.html'))) { |
| 61 | return m.reply('File index.html tidak ditemukan dalam struktur ZIP.'); |
| 62 | } |
| 63 | } else if (/html/.test(mime)) { |
| 64 | m.reply('⏳ Sedang memproses file HTML, mohon tunggu...'); |
| 65 | const content = await quotedFile.download(); |
| 66 | filesToUpload.push({ file: 'index.html', data: content.toString('base64'), encoding: 'base64' }); |
| 67 | } else { |
| 68 | return m.reply('File tidak dikenali. Kirim file .zip atau .html.'); |
| 69 | } |
| 70 | |
| 71 | const headers = { |
| 72 | Authorization: `Bearer ${token}`, |
| 73 | 'Content-Type': 'application/json' |
| 74 | }; |
| 75 | |
| 76 | await axios.post('https://api.vercel.com/v9/projects', { name: webName }, { headers }).catch(() => {}); |
| 77 | |
| 78 | try { |
| 79 | const deployRes = await axios.post('https://api.vercel.com/v13/deployments', { |
| 80 | name: webName, |
| 81 | project: webName, |
| 82 | files: filesToUpload, |
| 83 | projectSettings: { framework: null }, |
| 84 | target: 'production' |
| 85 | }, { headers }); |
| 86 | |
| 87 | const deployData = deployRes.data; |
| 88 | if (!deployData || !deployData.url) { |
| 89 | console.log('Deploy Error:', deployData); |
| 90 | return m.reply(`Gagal deploy ke Vercel.`); |
| 91 | } |
| 92 | |
| 93 | m.reply(`✅ Website berhasil dibuat! |
| 94 | |
| 95 | 🌐 URL: https://${webName}.vercel.app`); |
| 96 | } catch (e) { |
| 97 | console.error(e.response?.data || e) |
| 98 | m.reply(`Gagal Deploy: ${e.response?.data?.error?.message || e.message}`) |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | handler.help = ['deployweb']; |
| 103 | handler.tags = ['owner']; |
| 104 | handler.command = ['deployweb', 'deploy2']; |
| 105 | handler.owner = true; |
| 106 | |
| 107 | export default handler; |
Diskusi & Komentar0
Belum ada komentar — jadilah yang pertama memberikan masukan atau diskusi kode.
Masuk dengan akun GitHub untuk menulis komentar dan berdiskusi.