wolfyflutter

59. tmpfiles.org [uploader]

Aug 24th, 2025 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.70 KB | Source Code | 0 0
  1. /*
  2.   base : https://tmpfiles.org/
  3.   note : temporary file, bertahan 1 jam, max file 100MB
  4.   node : v24.5.0
  5.   by   : wolep
  6. */
  7.  
  8. import fs from "fs"
  9.  
  10. const upload = async function (buffer, ext = '.bin'){
  11.     const origin = 'https://tmpfiles.org'
  12.     const r1 = await fetch(origin)
  13.     const cookie = r1.headers.getSetCookie().map(v => v.split('; ')[0]).join('; ')
  14.  
  15.     const html = await r1.text()
  16.     const token = html.match(/token" value="(.+?)"/)?.[1]
  17.     console.log('token', token)
  18.  
  19.     const file = new File([buffer], Date.now() + ext)
  20.     const formData = new FormData()
  21.     formData.append('_token', token)
  22.     formData.append('upload', 'Upload')
  23.     formData.append('file',file)
  24.     console.log('uploading', file.name)
  25.     const r2 = await fetch(origin,{
  26.         headers : {
  27.             cookie
  28.         },
  29.         body : formData,
  30.         method : 'post'
  31.     })
  32.     const html2 = await r2.text()
  33.     const filename = html2.match(/Filename(?:.+?)<td>(.+?)<\/td>/s)?.[1]
  34.     const size = html2.match(/Size(?:.+?)<td>(.+?)<\/td>/s)?.[1]
  35.     const url = html2.match(/URL(?:.+?)href="(.+?)"/s)?.[1]
  36.     const expiresAt = html2.match(/Expires at(?:.+?)<td>(.+?)<\/td>/s)?.[1]
  37.     if(!url) throw Error ('gagal mendapatkan url download')
  38.     const result = {filename, size, expiresAt, url}
  39.     return result
  40.  
  41. }
  42.  
  43. // cara pakai
  44. const buffer = fs.readFileSync('./ubah_kertas_ke_A4.mp4')
  45. upload(buffer)
  46. .then(console.log)
  47. .catch(e => console.log(e.message))
  48.  
  49.  
  50.  
  51. /* output
  52. {
  53.   filename: '1756082822034.bin',
  54.   size: '713.06 KB',
  55.   expiresAt: '2025-08-25 01:47 UTC',
  56.   url: 'http://tmpfiles.org/dl/...........22034.bin'
  57. }
  58.  
  59. atauu...
  60. tambahkan ekstensi manual
  61. upload(buffer, '.mp4')
  62.  
  63. */
Tags: Uploader
Advertisement
Add Comment
Please, Sign In to add comment