forked from encrypt/toot
Added altrnative text for images support
This commit is contained in:
parent
70d5ecc217
commit
42193183c9
1 changed files with 21 additions and 13 deletions
34
toot.sh
34
toot.sh
|
@ -9,6 +9,7 @@ toot_help(){
|
|||
echo "toot [args..] your status update"
|
||||
echo "Arguments: "
|
||||
echo " -i=, --image= select file image to post"
|
||||
echo " -a=, --alt= the image description for disabilities"
|
||||
echo " -t=, --token= your API access token"
|
||||
echo " -s=, --server= mastodon server"
|
||||
echo ""
|
||||
|
@ -23,34 +24,37 @@ then
|
|||
fi
|
||||
|
||||
toot_upload_image(){
|
||||
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 image="$1"
|
||||
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" ]
|
||||
then
|
||||
echo $id
|
||||
return 0
|
||||
echo $id
|
||||
return 0
|
||||
fi
|
||||
echo "Image upload: Something went wrong"
|
||||
exit 1
|
||||
|
||||
}
|
||||
|
||||
toot_post(){
|
||||
status="$1"
|
||||
image="$2"
|
||||
data="status=$status&media_ids[]=$image"
|
||||
error=$(curl --header "Authorization: Bearer $MASTODON_TOKEN" -sS -X POST https://$MASTODON_SERVER/api/v1/statuses -d "$data" | jq -r .error)
|
||||
local status="$1"
|
||||
local image="$2"
|
||||
local data="status=$status&media_ids[]=$image"
|
||||
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" ]
|
||||
then
|
||||
echo "Yay!"
|
||||
echo "Yay!"
|
||||
else
|
||||
echo $error
|
||||
exit 1
|
||||
echo $error
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
image_to_toot=""
|
||||
image_alt=""
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
|
@ -73,6 +77,10 @@ do
|
|||
MASTODON_SERVER="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
-a=*|--alt=*)
|
||||
image_alt="${arg#*=}"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
@ -86,7 +94,7 @@ fi
|
|||
|
||||
if [ -n $image_to_toot ] && [ -f $image_to_toot ]
|
||||
then
|
||||
image_id=$(toot_upload_image $image_to_toot)
|
||||
image_id=$(toot_upload_image "$image_to_toot" "$image_alt")
|
||||
fi
|
||||
|
||||
toot_post "$*" "$image_id"
|
||||
|
|
Loading…
Reference in a new issue