upload media ke github dan menjadi link raw
Contributed by
@mifyaw1 contribution
mifyaw
javascript
67
12
ā
23 Agu 2026
Code
import axios from 'axios'
const headers = token => ({
Authorization: `token ${token}`,
Accept: 'application/vnd.github+json',
'User-Agent': 'WhatsAppBot'
})
const handler = async (m, { sock }) => {
const q = m.quoted || m
const mime = (q.msg || q).mimetype || ''
if (!mime) return m.reply('Reply media yang ingin diupload.')
const token = global.tokengh
if (!token) return m.reply('Token GitHub belum diatur.')
const repo = 'cdn'
try {
m.reply('ā³ Uploading...')
const { data: me } = await axios.get(
'https://api.github.com/user',
{ headers: headers(token) }
)
const owner = me.login
try {
await axios.get(
`https://api.github.com/repos/${owner}/${repo}`,
{ headers: headers(token) }
)
} catch (e) {
if (e.response?.status === 404) {
await axios.post(
'https://api.github.com/user/repos',
{
name: repo,
private: false,
auto_init: true
},
{
headers: headers(token)
}
)
} else {
throw e
}
}
const buffer = await q.download()
const ext = '.' + (mime || 'bin')
.split('/')
.pop()
.replace('jpeg', 'jpg')
.replace('mpeg', 'mp3')
const filename = `${Date.now().toString(36)}${ext}`
const path = `uploads/${filename}`
await axios.put(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
{
message: `Upload ${filename}`,
content: buffer.toString('base64')
},
{
headers: headers(token)
}
)
const raw = `https://raw.githubusercontent.com/${owner}/${repo}/main/${path}`
await sock.sendMessage(
m.chat,
{
text: `ā
Upload Berhasil
${raw}`
},
{ quoted: m }
)
} catch (e) {
m.reply(`ā ${e.response?.data?.message || e.message}`)
}
}
handler.help = ['tourlgithub']
handler.tags = ['tools']
handler.command = ['tourlgh', 'tourl']
handler.owner = true
export default handlerRating
Gimana snippet ini menurutmu?
Embed ke website / blog
<iframe src="https://qrtzcode.vercel.app/api/embed/tools/tourl-github" style="width:100%;height:400px;border:none;border-radius:12px;"></iframe>