Imgupload.hex

mIRC Scripting Guest 6 Views Size: 2.91 KB Posted on: Sep 16, 26 @ 11:52 AM
  1. ; Image uploader for HexDroid
  2. ;
  3. ; /img   picks an image and uploads it, then sends the URL to the channel.
  4. ; /imgme does the same but shows the URL only to you.
  5. ;
  6. ; Written for the Paste Image Uploader PHP endpoint, which:
  7. ;   - reads the file from the form field "images"
  8. ;   - strips EXIF when the form field "strip_exif" is set
  9. ;   - answers 200 with {"results":[{"success":true,"filePath":"/img/img_x.png",...}]}
  10. ;     or {"results":[{"success":false,"error":"..."}]}
  11. ;   - returns a site-absolute path, not a full URL, so %img_base supplies the origin
  12. ;
  13. ; SETTINGS
  14. ;   %img_ep     exact upload URL including the file name. A directory URL answers 301 and
  15. ;               the upload is not redirected, on purpose: a redirect to another host would
  16. ;               send your file somewhere HexDroid never checked.
  17. ;   %img_base   scheme and host the returned path hangs off, no trailing slash.
  18. ;   %img_field  form field the server reads the file from.
  19. ;   %img_auth   optional, a whole header line, e.g. Authorization: Bearer abc123
  20. ;
  21. ; The picker never opens on its own: HexDroid asks first, and you choose the file. The
  22. ; script is handed a token for that one file, not a path, and can read nothing else.
  23.  
  24. on LOAD {
  25.   set %img_ep https://paste.boxlabs.uk/img/index.php
  26.   set %img_base https://paste.boxlabs.uk
  27.   set %img_field images
  28.   ;set %img_auth
  29. }
  30.  
  31. alias img {
  32.   if ($buffer == *server*) {
  33.     echo $buffer *** /img needs a channel or query. Use /imgme here.
  34.     return
  35.   }
  36.   media.pick -m image/* img_picked $buffer public
  37. }
  38.  
  39. alias imgme {
  40.   media.pick -m image/* img_picked $buffer private
  41. }
  42.  
  43. on SIGNAL:img_picked {
  44.   ; $1 buffer, $2 public|private
  45.   if ($mediaok != true) { return }
  46.   toast Uploading $medianame
  47.   ; strip_exif matters for photos: without it the server keeps the GPS tags.
  48.   if ($len(%img_auth) == 0) {
  49.     media.upload -f %img_field -p strip_exif=1 %img_ep $mediatoken img_done $1 $2
  50.   }
  51.   else {
  52.     media.upload -f %img_field -p strip_exif=1 -h %img_auth %img_ep $mediatoken img_done $1 $2
  53.   }
  54. }
  55.  
  56. on SIGNAL:img_done {
  57.   if ($httpok != true) {
  58.     if ($httpstatus == 0) {
  59.       echo $1 *** upload failed: $httperror
  60.       return
  61.     }
  62.     echo $1 *** upload failed ($httpstatus) $left($trim($re_replace($httpbody, \s+, " ")), 200)
  63.     return
  64.   }
  65.  
  66.   ; A 2xx is not success here: this endpoint reports its failures in a 200 body.
  67.   set -l %err $json($httpbody, results.0.error)
  68.   if ($len(%err) > 0) {
  69.     echo $1 *** upload rejected: %err
  70.     return
  71.   }
  72.  
  73.   set -l %path $trim($json($httpbody, results.0.filePath))
  74.   if ($len(%path) == 0) {
  75.     echo $1 *** uploaded, but no path in the reply: $left($trim($re_replace($httpbody, \s+, " ")), 200)
  76.     return
  77.   }
  78.   set -l %url %img_base%path
  79.   if ($left(%path, 8) == https://) { set -l %url %path }
  80.   if ($left(%path, 7) == http://) { set -l %url %path }
  81.  
  82.   if ($2 == public) { msg $1 %url }
  83.   else { echo $1 %url }
  84. }

Raw Paste

Comments 0
Login to post a comment.
  • No comments yet. Be the first.
Login to post a comment. Login or Register
We use cookies. To comply with GDPR in the EU and the UK we have to show you these.

We use cookies and similar technologies to keep this website functional (including spam protection via Google reCAPTCHA or Cloudflare Turnstile), and — with your consent — to measure usage and show ads. See Privacy.