forked from encrypt/toot
Added content warning and image alternative text
This commit is contained in:
parent
f534da95fe
commit
6e44918e57
1 changed files with 47 additions and 32 deletions
79
toot.sh
79
toot.sh
|
@ -1,16 +1,18 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# WTFPL!
|
# WTFPL!
|
||||||
|
|
||||||
MASTODON_TOKEN=ENV["MASTODON_TOKEN"]
|
MASTODON_TOKEN=$MASTODON_TOKEN
|
||||||
MASTODON_SERVER="mastodon.bida.im"
|
MASTODON_SERVER="mastodon.bida.im"
|
||||||
|
|
||||||
toot_help(){
|
toot_help(){
|
||||||
echo "toot [args..] your status update"
|
echo "toot [args..] your status update"
|
||||||
echo "Argouments: "
|
echo "Arguments: "
|
||||||
echo " -i=, --image= select file image to post"
|
echo " -i=, --image= select file image to post"
|
||||||
|
echo " -a=, --alt= the image description for disabilities"
|
||||||
echo " -t=, --token= your API access token"
|
echo " -t=, --token= your API access token"
|
||||||
echo " -s=, --server= mastodon server"
|
echo " -s=, --server= mastodon server"
|
||||||
|
echo " -w, --warn the image is marked as sensitive"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Mastodon server can be set in ~/.tootrc otherwise it will be defaulted to $MASTODON_SERVER"
|
echo "Mastodon server can be set in ~/.tootrc otherwise it will be defaulted to $MASTODON_SERVER"
|
||||||
echo "The token can be passed as, cli argument, var in ~/.tootrc, env var (in this priority order)"
|
echo "The token can be passed as, cli argument, var in ~/.tootrc, env var (in this priority order)"
|
||||||
|
@ -23,36 +25,41 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
toot_upload_image(){
|
toot_upload_image(){
|
||||||
image="$1"
|
local image="$1"
|
||||||
id=$(curl --header "Authorization: Bearer $MASTODON_TOKEN" -sS -X POST https://$MASTODON_SERVER/api/v1/media -F "file=@$image" | jq -r .id)
|
local description="$2"
|
||||||
|
local desc_data="description=$description"
|
||||||
|
local data="file=@$image"
|
||||||
|
local id=$(curl --header "Authorization: Bearer $MASTODON_TOKEN" -sS -X POST https://$MASTODON_SERVER/api/v1/media -F "$desc_data" -F "$data" | jq -r .id)
|
||||||
if [ $? -eq 0 ] && [ -n "$id" ]
|
if [ $? -eq 0 ] && [ -n "$id" ]
|
||||||
then
|
then
|
||||||
echo $id
|
echo $id
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "Image upload: Something went wrong"
|
echo "Image upload: Something went wrong"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toot_post(){
|
toot_post(){
|
||||||
status="$1"
|
local status="$1"
|
||||||
image="$2"
|
local image="$2"
|
||||||
data="status=$status&media_ids[]=$image"
|
local sensitive="$3"
|
||||||
error=$(curl --header "Authorization: Bearer $MASTODON_TOKEN" -sS -X POST https://$MASTODON_SERVER/api/v1/statuses -d "$data" | jq -r .error)
|
local data="status=$status&media_ids[]=$image&sensitive=$sensitive"
|
||||||
|
local error=$(curl --header "Authorization: Bearer $MASTODON_TOKEN" -sS -X POST https://$MASTODON_SERVER/api/v1/statuses -d "$data" | jq -r .error)
|
||||||
if [ "$error" = "null" ]
|
if [ "$error" = "null" ]
|
||||||
then
|
then
|
||||||
echo "Yay!"
|
echo "Yay!"
|
||||||
else
|
else
|
||||||
echo $error
|
echo $error
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
image_to_toot=""
|
image_to_toot=""
|
||||||
|
image_alt=""
|
||||||
|
sensitive="false"
|
||||||
|
|
||||||
if [ -z "$@" ]
|
if [ $# -eq 0 ]
|
||||||
then
|
then
|
||||||
toot_help
|
toot_help
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -61,20 +68,28 @@ fi
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
do
|
do
|
||||||
case $arg in
|
case $arg in
|
||||||
-i=*|--image=*)
|
-i=*|--image=*)
|
||||||
image_to_toot="${arg#*=}"
|
image_to_toot="${arg#*=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-t=*|--token=*)
|
-t=*|--token=*)
|
||||||
MASTODON_TOKEN="${arg#*=}"
|
MASTODON_TOKEN="${arg#*=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-s=*|--server=*)
|
-s=*|--server=*)
|
||||||
MASTODON_SERVER="${arg#*=}"
|
MASTODON_SERVER="${arg#*=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
-a=*|--alt=*)
|
||||||
;;
|
image_alt="${arg#*=}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-w|--warn)
|
||||||
|
sensitive="true"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -86,7 +101,7 @@ fi
|
||||||
|
|
||||||
if [ -n $image_to_toot ] && [ -f $image_to_toot ]
|
if [ -n $image_to_toot ] && [ -f $image_to_toot ]
|
||||||
then
|
then
|
||||||
image_id=$(toot_upload_image $image_to_toot)
|
image_id=$(toot_upload_image "$image_to_toot" "$image_alt")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
toot_post "$*" "$image_id"
|
toot_post "$*" "$image_id" "$sensitive"
|
Loading…
Reference in a new issue