Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- base : https://tmpfiles.org/
- note : temporary file, bertahan 1 jam, max file 100MB
- node : v24.5.0
- by : wolep
- */
- import fs from "fs"
- const upload = async function (buffer, ext = '.bin'){
- const origin = 'https://tmpfiles.org'
- const r1 = await fetch(origin)
- const cookie = r1.headers.getSetCookie().map(v => v.split('; ')[0]).join('; ')
- const html = await r1.text()
- const token = html.match(/token" value="(.+?)"/)?.[1]
- console.log('token', token)
- const file = new File([buffer], Date.now() + ext)
- const formData = new FormData()
- formData.append('_token', token)
- formData.append('upload', 'Upload')
- formData.append('file',file)
- console.log('uploading', file.name)
- const r2 = await fetch(origin,{
- headers : {
- cookie
- },
- body : formData,
- method : 'post'
- })
- const html2 = await r2.text()
- const filename = html2.match(/Filename(?:.+?)<td>(.+?)<\/td>/s)?.[1]
- const size = html2.match(/Size(?:.+?)<td>(.+?)<\/td>/s)?.[1]
- const url = html2.match(/URL(?:.+?)href="(.+?)"/s)?.[1]
- const expiresAt = html2.match(/Expires at(?:.+?)<td>(.+?)<\/td>/s)?.[1]
- if(!url) throw Error ('gagal mendapatkan url download')
- const result = {filename, size, expiresAt, url}
- return result
- }
- // cara pakai
- const buffer = fs.readFileSync('./ubah_kertas_ke_A4.mp4')
- upload(buffer)
- .then(console.log)
- .catch(e => console.log(e.message))
- /* output
- {
- filename: '1756082822034.bin',
- size: '713.06 KB',
- expiresAt: '2025-08-25 01:47 UTC',
- url: 'http://tmpfiles.org/dl/...........22034.bin'
- }
- atauu...
- tambahkan ekstensi manual
- upload(buffer, '.mp4')
- */
Advertisement
Add Comment
Please, Sign In to add comment