Added attachment support in write statuses; alias post_request; state code sending

This commit is contained in:
localhost_frssoft 2022-04-13 23:34:03 +03:00
parent 093e8b5ea4
commit 60daf22e59

View file

@ -21,6 +21,7 @@ if [ -n "$auth" ]; then
{
curl -s --compressed -H "Authorization: Bearer $auth" $1
}
alias post_request="curl -s --compressed -X POST -H \"Authorization: Bearer $auth\""
echo '+Authorized account+'
else
default_curl_opt()
@ -119,12 +120,12 @@ backup_restore_menu()
backup_api_create()
{
curl -s --compressed -X POST -H "Authorization: Bearer $auth" "$instance_point/pleroma/backups"
post_request "$instance_point/pleroma/backups"
}
backup_api_list()
{
curl -s --compressed -H "Authorization: Bearer $auth" "$instance_point/pleroma/backups"
default_curl_opt "$instance_point/pleroma/backups"
}
follow_api_export()
@ -208,19 +209,19 @@ mutes_api_export()
follow_api_import()
{
curl -v --compressed -H "Authorization: Bearer $auth" "$instance_point_pleroma/follow_import" \
post_request "$instance_point_pleroma/follow_import" \
--data 'list=@restore/friends.csv'
}
blocks_api_import()
{
curl -s --compressed -H "Authorization: Bearer $auth" "$instance_point_pleroma/blocks_import" \
post_request "$instance_point_pleroma/blocks_import" \
--data 'list=@restore/blocks.csv'
}
mutes_api_import()
{
curl -s --compressed -H "Authorization: Bearer $auth" "$instance_point_pleroma/mutes_import" \
post_request "$instance_point_pleroma/mutes_import" \
--data 'list=@restore/mutes.csv'
}
#[MIGRATION SECTION END]
@ -384,16 +385,36 @@ timeline_menu()
share_api_status()
{
curl -w "%{http_code}" -X POST -s --compressed -H "Authorization: Bearer $auth" --url $instance_point/statuses/$1/reblog --output /dev/null
post_request -w "%{http_code}" --url $instance_point/statuses/$1/reblog --output /dev/null
}
write_api_status()
{
curl -s --compressed -H "Authorization: Bearer $auth" --url $instance_point/statuses \
--data-urlencode "status=$1" \
--data-urlencode "content_type=$content_type" \
--data-urlencode "visibility=$status_visibility" \
--data-urlencode "in_reply_to_id=$replyto"
if [ -n "$mediaattach" ]; then
media=$(upload_api_media | jj id)
post_request -w "%{http_code}" --url $instance_point/statuses \
--data-urlencode "status=$1" \
--data-urlencode "content_type=$content_type" \
--data-urlencode "visibility=$status_visibility" \
--data-urlencode "in_reply_to_id=$replyto" \
--data-urlencode "media_ids[]=$media" \
--output /dev/null
echo $http_code
else
post_request -w "%{http_code}" --url $instance_point/statuses \
--data-urlencode "status=$1" \
--data-urlencode "content_type=$content_type" \
--data-urlencode "visibility=$status_visibility" \
--data-urlencode "in_reply_to_id=$replyto" \
--output /dev/null
echo $http_code
fi
}
upload_api_media()
{
post_request --url $instance_point/media \
--form "file=$mediaattach"
}
write_status_menu()
@ -402,6 +423,7 @@ write_status_menu()
content_type="$default_content_type"
status_visibility="$default_visibility"
replyto=$1
mediaattach=
sub_menu_lvl=1
while [ $sub_menu_lvl -eq 1 ]; do
clear
@ -414,10 +436,20 @@ write_status_menu()
if [ -n "$replyto" ]; then
echo "Reply to: $replyto"
fi
wrirepostmenu=$(echo "Write\nSend\nChange type\nVisiblity\nMain menu" | fzy)
if [ -n "$mediaattach" ]; then
echo "Attachments: $mediaattach"
fi
if [ -n "http_code" ]; then
echo "Send state: $http_code"
fi
wrirepostmenu=$(echo "Write\nSend\nAdd attach\nChange type\nVisiblity\nMain menu" | fzy)
case $wrirepostmenu in
"Write") echo > tmp_status.md; $EDITOR tmp_status.md ;;
"Send") write_api_status "$(cat tmp_status.md)" | jj -p ;;
"Send") http_code=$(write_api_status "$(cat tmp_status.md)") ;;
"Add attach")
echo 'Input path to attach (ex. @image.png or @/full/path/to/attach.png)'
read mediaattach
;;
"Change type") content_type=$(echo 'text/plain\ntext/markdown\ntext/html' | fzy) ;;
"Visiblity")
status_visibility=$(echo 'public\nunlisted\nlocal\nprivate\ndirect\nlist' | fzy)
@ -460,7 +492,7 @@ notif_api_get_all()
notif_api_remove_all()
{
curl -X POST --compressed -H "Authorization: Bearer $auth" --url $instance_point/notifications/clear
post_request --url $instance_point/notifications/clear
}
menu_write_status='Write status'
@ -520,6 +552,7 @@ case $main_menu in
{
curl -s --compressed -H "Authorization: Bearer $auth" $1
}
alias post_request="curl -s --compressed -X POST -H \"Authorization: Bearer $auth\""
echo '+Authorized account+'
else
default_curl_opt()