12345678910111213141516171819202122232425262728293031323334353637 |
- #!/usr/bin/env elvish
-
- resp = [&]
- id = (from-json <~/sns/imgur.json)[SolitudeAnon][id]
- command = [-sLX POST 'https://api.imgur.com/3/image' --data-binary '@-' -H "Authorization: Client-ID "$id ]
- argn = (count $args)
-
- if (and (> $argn 0) (eq $args[0] -d)) {
- if (== $argn 1) {
- echo Provide deletion hash
- exit 1
- }
- resp = (curl -sLX DELETE 'https://api.imgur.com/3/image/'$args[1] -H \
- 'Authorization: Client-ID '$id | from-json)
- if (and (has-key $resp success) (eq $resp[success] $true)) {
- echo Image deleted
- } else {
- echo Failed to delete image
- exit 1
- }
- } else {
- if (not-eq ?(tty -s) $ok) {
- resp = (all | base64 | curl $@command | from-json)
- } elif (> $argn 0) {
- resp = (base64 $args[0] | curl $@command | from-json)
- } else {
- exit 1
- }
-
- if (and (has-key $resp success) (eq $resp[success] $true)) {
- echo Uploaded to $resp[data][link]
- echo Delete hash: $resp[data][deletehash]
- } else {
- echo Upload failed
- exit 1
- }
- }
|