Created
October 24, 2025 10:34
-
-
Save mifyow/404b2a9c331bc9971b2c291fdd648055 to your computer and use it in GitHub Desktop.
Uploaded via Mifinfinity-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fs from 'fs' | |
| import axios from 'axios' | |
| import crypto from 'crypto' | |
| import { fileTypeFromBuffer } from 'file-type' | |
| const githubToken = 'Github_token' | |
| const owner = 'username_github' | |
| const branch = 'main' | |
| let repos = ['dat1','dat2','dat3','dat4'] | |
| async function ensureRepoExists(repo) { | |
| try { | |
| await axios.get(https://api.github.com/repos/${owner}/${repo}, { | |
| headers: { Authorization: Bearer ${githubToken} } | |
| }) | |
| } catch (e) { | |
| if (e.response?.status === 404) { | |
| await axios.post(https://api.github.com/user/repos, | |
| { name: repo, private: false }, | |
| { headers: { Authorization: Bearer ${githubToken} } } | |
| ) | |
| if (!repos.includes(repo)) repos.push(repo) | |
| } else throw e | |
| } | |
| } | |
| function generateRepoName() { | |
| return dat-${crypto.randomBytes(3).toString('hex')} | |
| } | |
| async function uploadFile(buffer) { | |
| const detected = await fileTypeFromBuffer(buffer) | |
| const ext = detected?.ext || 'bin' | |
| const code = crypto.randomBytes(3).toString('hex') | |
| const fileName = ${code}-${Date.now()}.${ext} | |
| const filePathGitHub = uploads/${fileName} | |
| const base64Content = Buffer.from(buffer).toString('base64') | |
| let targetRepo = repos[Math.floor(Math.random()*repos.length)] | |
| try { await ensureRepoExists(targetRepo) } | |
| catch { targetRepo = generateRepoName(); await ensureRepoExists(targetRepo) } | |
| await axios.put( | |
| https://api.github.com/repos/${owner}/${targetRepo}/contents/${filePathGitHub}, | |
| { message:Upload file ${fileName}, content:base64Content, branch }, | |
| { headers:{ Authorization:Bearer ${githubToken} } } | |
| ) | |
| return https://raw.githubusercontent.com/${owner}/${targetRepo}/${branch}/${filePathGitHub} | |
| } | |
| let handler = async (m,{conn}) => { | |
| try { | |
| const q = m.quoted ? m.quoted : m | |
| const mime = (q.msg || q).mimetype || '' | |
| if (!mime) return m.reply('Mana filenya') | |
| m.reply('Wait...') | |
| let buffer = await q.download() | |
| let url = await uploadFile(buffer) | |
| await m.reply(url) | |
| } catch(e) { | |
| m.reply(e.message) | |
| } | |
| } | |
| handler.help = ['tourl'] | |
| handler.command = ['tourl'] | |
| handler.tags = ['tools'] | |
| export default handler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment