Imgpaste.hex

HexDroid Scripting Detected Guest 6 Views Size: 2.78 KB Posted on: Nov 6, 26 @ 2:59 PM
  1. ; Image upload for HexDroid
  2. ; For websites that use https://phpaste.sourceforge.io
  3. ;
  4. ; /img   picks an image and uploads it, then sends the link to the channel.
  5. ; /imgme does the same but shows the link only to you.
  6. ;
  7. ; Uploads through the Paste API (api.php?action=upload), which:
  8. ;   - takes your API key, from Profile > API Keys on the site; sites that allow
  9. ;     guest uploads also take uploads without one
  10. ;   - reads the file from the form field "file"
  11. ;   - removes EXIF and GPS tags unless strip_exif=0 is sent
  12. ;   - answers 201 with {"success":true,"upload":{"file":"https://.../img/<key>.png",...}}
  13. ;     or an error status with {"success":false,"error":"..."}
  14. ;
  15. ; SETTINGS
  16. ;   %img_ep     exact upload URL. Redirects are not followed, so use the final URL.
  17. ;   %img_field  form field the server reads the file from.
  18. ;   %img_auth   optional, your API key as a whole header line: Authorization: Bearer <key>
  19. ;               (X-API-Key: <key> also works). Leave empty to upload as a guest.
  20. ;
  21. ; Globals are shared by every script, so the settings carry an img_ prefix.
  22. ;
  23. ; The picker never opens on its own: HexDroid asks first, and you choose the file. The
  24. ; script is handed a token for that one file, not a path, and can read nothing else.
  25.  
  26. on LOAD {
  27.   set %img_ep https://paste.boxlabs.uk/api.php?action=upload
  28.   set %img_field file
  29.   set %img_auth
  30. }
  31.  
  32. alias img {
  33.   if ($buffer == *server*) {
  34.     echo $buffer *** /img needs a channel or query. Use /imgme here.
  35.     return
  36.   }
  37.   media.pick -m image/* img_picked $buffer public
  38. }
  39.  
  40. alias imgme {
  41.   media.pick -m image/* img_picked $buffer private
  42. }
  43.  
  44. on SIGNAL:img_picked {
  45.   ; $1 buffer, $2 public|private
  46.   if ($mediaok != true) { return }
  47.   toast Uploading $medianame
  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.   ; $1 buffer, $2 public|private
  58.   if ($httpok != true) {
  59.     if ($httpstatus == 0) {
  60.       echo $1 *** upload failed: $httperror
  61.       return
  62.     }
  63.     if ($httpstatus == 401) {
  64.       echo $1 *** this site needs an API key: add it to img_auth in the LOAD block
  65.       return
  66.     }
  67.     set -l %err $json($httpbody, error)
  68.     if ($len(%err) > 0) {
  69.       echo $1 *** upload failed ($httpstatus): %err
  70.       return
  71.     }
  72.     echo $1 *** upload failed ($httpstatus) $left($trim($re_replace($httpbody, \s+, " ")), 200)
  73.     return
  74.   }
  75.  
  76.   set -l %url $trim($json($httpbody, upload.file))
  77.   if ($len(%url) == 0) {
  78.     echo $1 *** uploaded, but no link in the reply: $left($trim($re_replace($httpbody, \s+, " ")), 200)
  79.     return
  80.   }
  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.