; Image upload for HexDroid ; For websites that use https://phpaste.sourceforge.io ; ; /img picks an image and uploads it, then sends the link to the channel. ; /imgme does the same but shows the link only to you. ; ; Uploads through the Paste API (api.php?action=upload), which: ; - takes your API key, from Profile > API Keys on the site; sites that allow ; guest uploads also take uploads without one ; - reads the file from the form field "file" ; - removes EXIF and GPS tags unless strip_exif=0 is sent ; - answers 201 with {"success":true,"upload":{"file":"https://.../img/.png",...}} ; or an error status with {"success":false,"error":"..."} ; ; SETTINGS ; %img_ep exact upload URL. Redirects are not followed, so use the final URL. ; %img_field form field the server reads the file from. ; %img_auth optional, your API key as a whole header line: Authorization: Bearer ; (X-API-Key: also works). Leave empty to upload as a guest. ; ; Globals are shared by every script, so the settings carry an img_ prefix. ; ; The picker never opens on its own: HexDroid asks first, and you choose the file. The ; script is handed a token for that one file, not a path, and can read nothing else. on LOAD { set %img_ep https://paste.boxlabs.uk/api.php?action=upload set %img_field file set %img_auth } alias img { if ($buffer == *server*) { echo $buffer *** /img needs a channel or query. Use /imgme here. return } media.pick -m image/* img_picked $buffer public } alias imgme { media.pick -m image/* img_picked $buffer private } on SIGNAL:img_picked { ; $1 buffer, $2 public|private if ($mediaok != true) { return } toast Uploading $medianame if ($len(%img_auth) == 0) { media.upload -f %img_field -p strip_exif=1 %img_ep $mediatoken img_done $1 $2 } else { media.upload -f %img_field -p strip_exif=1 -h %img_auth %img_ep $mediatoken img_done $1 $2 } } on SIGNAL:img_done { ; $1 buffer, $2 public|private if ($httpok != true) { if ($httpstatus == 0) { echo $1 *** upload failed: $httperror return } if ($httpstatus == 401) { echo $1 *** this site needs an API key: add it to img_auth in the LOAD block return } set -l %err $json($httpbody, error) if ($len(%err) > 0) { echo $1 *** upload failed ($httpstatus): %err return } echo $1 *** upload failed ($httpstatus) $left($trim($re_replace($httpbody, \s+, " ")), 200) return } set -l %url $trim($json($httpbody, upload.file)) if ($len(%url) == 0) { echo $1 *** uploaded, but no link in the reply: $left($trim($re_replace($httpbody, \s+, " ")), 200) return } if ($2 == public) { msg $1 %url } else { echo $1 %url } }