Fixed a bunch of annoying backslashes.

This commit is contained in:
Zergling_man 2023-07-02 19:28:33 +10:00
parent eb656567cf
commit c0ab52f1c3
5 changed files with 14 additions and 13 deletions

4
api.sh
View File

@ -3,6 +3,6 @@ baseurl(){ if [ -z $INSEC ]; then sec=s; fi; echo "http$sec://$INSTANCE/api/v3/"
#Generics
get(){ curl -s "$(baseurl)$1?${*:3}" | jq "$2"; }
getauth(){ get "$1" "$2" "auth=$TOKE&${*:3}"; }
post(){ curl -s "$(baseurl)$1" --json "$(echo ${*:2} | jq .+{\"auth\":\"$TOKE\"})"; }
post(){ curl -s "$(baseurl)$1" --json "$(echo ${*:2} | jq '.+{"auth":"'$TOKE'"}')"; }
# I'm just gonna clone this thing rather than try to palm the -X PUT into post. I can fix it later.
put(){ curl -sX PUT "$(baseurl)$1" --json "$(echo ${*:2} | jq .+{\"auth\":\"$TOKE\"})"; }
put(){ curl -sX PUT "$(baseurl)$1" --json "$(echo ${*:2} | jq '.+{"auth":"'$TOKE'"}')"; }

View File

@ -2,8 +2,9 @@
whoami(){ echo $INSTANCE $TOKE; }
login()
{
post "user/login" "{\"username_or_email\":\"$1\",\"password\":\"$2\"}"
post "user/login" '{"username_or_email":"'$1'","password":"'$2'"}'
}
register()
{
get "site" ".site_view.site | .open_registration,.require_email_verification,.require_application,.application_question" | jq -r . | read reg em app appq
@ -17,7 +18,7 @@ register()
if [ ! reg_pw == reg_pw2 ]; then echo "passwords don't match (continuing anyway, expect failure later though)"; fi
namedget reg_email "Email address $em"
if [ $app == true ]; then namedget reg_appa "Application question: $appq"; fi
result="$(post "user/register" "{\"username\":\"$reg_username\",\"password\":\"$reg_pw\",\"password_verify\":\"$reg_pw2\",\"email\":\"$reg_email\",\"answer\":\"$reg_appa\"}")"
result="$(post "user/register" '{"username":"'$reg_username'","password":"'$reg_pw'","password_verify":"'$reg_pw2'","email":"'$reg_email'","answer":"'$reg_appa'"}')"
if [ ! $(jq .error <<< "$result") == "captcha_incorrect" ]; then
jq <<< "$result"; exit;
fi
@ -26,5 +27,5 @@ register()
jq -r '.wav' <<< "$a" | base64 -d > "captcha.wav"
jq -r '.png' <<< "$a" | base64 -d > "captcha.png"
namedget reg_captcha "Please open captcha.wav and captcha.png and input the text - in that order, no spaces"
post "user/register" "{\"username\":\"$reg_username\",\"password\":\"$reg_pw\",\"password_verify\":\"$reg_pw2\",\"email\":\"$reg_email\",\"answer\":\"$reg_appa\",\"captcha_uuid\":\"$reg_uuid\",\"captcha_answer\":\"$reg_captcha\"}"
post "user/register" '{"username":"'$reg_username'","password":"'$reg_pw'","password_verify":"'$reg_pw2'","email":"'$reg_email'","answer":"'$reg_appa'","captcha_uuid":"'$reg_uuid'","captcha_answer":"'$reg_captcha'"}'
}

View File

@ -16,8 +16,8 @@ pending()
namedget ans "Accept? (y)es (n)o (s)kip"
done
case $ans in
y) put "admin/registration_application/approve" "{\"id\":$appid,\"approve\":true}";;
n) namedget rejected "Why not?" true; put "admin/registration_application/approve" "{\"id\":$appid,\"deny_reason\":\"$rejected\",\"approve\":false}";;
y) put "admin/registration_application/approve" '{"id":'$appid',"approve":true}';;
n) namedget rejected "Why not?" true; put "admin/registration_application/approve" '{"id":'$appid',"deny_reason":"'$rejected'","approve":false}';;
esac
done
}

View File

@ -1,4 +1,4 @@
#Community hoardan
follow(){ post "community/follow" "{\"community_id\":$1,\"follow\":true}"; }
unfollow(){ post "community/follow" "{\"community_id\":$1,\"follow\":false}"; }
follow(){ post "community/follow" '{"community_id":'$1',"follow":true}'; }
unfollow(){ post "community/follow" '{"community_id":'$1',"follow":false}'; }
following(){ echo "use <home> instead"; } # Maybe this will help.

View File

@ -1,7 +1,7 @@
#Post hoardan
save(){ put "post/save" "{\"post_id\":$1,\"save\":true}"; }
unsave(){ put "post/save" "{\"post_id\":$1,\"save\":false}"; }
save(){ put "post/save" '{"post_id":'$1',"save":true}'; }
unsave(){ put "post/save" '{"post_id":'$1',"save":false}'; }
load(){ getauth "post/list" ".posts | .[] | $postsummary" "type_=All&saved_only=true"; }
#Postan
freepost(){ getbody; post "post" "{\"community_id\":$1,\"name\":\"${*:2}\",\"body\":\"$body\"}"; }
shitpost(){ getbody; postid=$1; parentid=$2; post "comment" "{\"post_id\":$postid,\"parent_id\":$parentid,\"content\":\"$body\"}"; }
freepost(){ getbody; post "post" '{"community_id":'$1',"name":"'${*:2}'","body":"'$body'"}'; }
shitpost(){ getbody; postid=$1; parentid=$2; if [ -z $parentid ]; then parentid=null; fi; post "comment" '{"post_id":'$postid',"parent_id":'$parentid',"content":"'$body'"}'; }