From b1cb700ef7c7e1678bd3c9b938487980d28b10a5 Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Tue, 2 Jul 2024 14:51:50 +1000 Subject: [PATCH] Lemmy finally fixed auth tokens to not be in the fucking query params --- PKGBUILD | 2 +- api.sh | 5 ++--- commands/admin.sh | 8 ++++---- commands/commands.sh | 2 +- commands/communities.sh | 2 +- commands/lurking.sh | 8 ++++---- commands/posts.sh | 2 +- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 6941215..b1e7986 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -2,7 +2,7 @@ #Well, it seems to work now. pkgname=clemmy -pkgver=0.1.7 +pkgver=0.2.0 pkgrel=1 pkgdesc='A pure bash client for lemmy, with multiaccount support.' arch=('any') diff --git a/api.sh b/api.sh index d30cd91..ddaf917 100644 --- a/api.sh +++ b/api.sh @@ -1,8 +1,7 @@ baseurl(){ if [ -z $INSEC ]; then sec=s; fi; echo "http$sec://$INSTANCE/api/v3/"; } # This needs to be a function so updates to INSTANCE affect it. This is a very old bug lmao #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'"}')"; } +get(){ curl -sH "Cookie:jwt=$TOKE" "$(baseurl)$1?${*:3}" | jq "${2:-.}"; } +post(){ curl -sH "Cookie:jwt=$TOKE" "$(baseurl)$1" --json "${*:2}"; } # 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'"}')"; } \ No newline at end of file diff --git a/commands/admin.sh b/commands/admin.sh index 9a94361..779aa23 100644 --- a/commands/admin.sh +++ b/commands/admin.sh @@ -1,13 +1,13 @@ pendcount() { - getauth "admin/registration_application/count" ".registration_applications" + get "admin/registration_application/count" ".registration_applications" } pending() { - applications=$(getauth "admin/registration_application/list" ".registration_applications" "unread_only=true") + applications=$(get "admin/registration_application/list" ".registration_applications" "unread_only=true") i=0 - app=$(jq .[$i] <<< "$applications") + app=$(jq ".[$i] // empty" <<< "$applications") while [ -n "$app" ]; do appid=$(jq -r .registration_application.id <<< "$app") jq '.registration_application.id, (.creator | .name,.published,.bio,"bot: "+.bot_account,"matrix: "+.matrix_user_id,.avatar,.banner), "captcha: "+.registration_application.answer' <<< "$app" @@ -23,4 +23,4 @@ pending() } addadmin(){ echo "stub"; } -remadmin(){ echo "stub"; } \ No newline at end of file +remadmin(){ echo "stub"; } diff --git a/commands/commands.sh b/commands/commands.sh index 964290d..05606e6 100644 --- a/commands/commands.sh +++ b/commands/commands.sh @@ -9,4 +9,4 @@ source $imps/commands/posts.sh source $imps/commands/admin.sh #Misc -deref(){ getauth "resolve_object" "" "q=$*"; } \ No newline at end of file +deref(){ get "resolve_object" "" "q=$*"; } \ No newline at end of file diff --git a/commands/communities.sh b/commands/communities.sh index f29ca4f..77d8d61 100644 --- a/commands/communities.sh +++ b/commands/communities.sh @@ -1,7 +1,7 @@ #Community hoardan follow(){ post "community/follow" '{"community_id":'$1',"follow":true}'; } unfollow(){ post "community/follow" '{"community_id":'$1',"follow":false}'; } -following(){ getauth "community/list" ".communities | $communities_jq" "type_=Subscribed"; } # Alright it's time +following(){ get "community/list" ".communities | $communities_jq" "type_=Subscribed"; } # Alright it's time comcreate(){ namedget desc "The community's display name (can be edited later)"; post "community" '{"name":"'$1'","title":"'"$desc"'"}'; } comedit(){ echo "stub"; } diff --git a/commands/lurking.sh b/commands/lurking.sh index 03ab8a3..4d46380 100644 --- a/commands/lurking.sh +++ b/commands/lurking.sh @@ -1,7 +1,7 @@ #Lurkan -notifs(){ getauth "user/replies" ".replies | reverse | $notifs_jq"; } +notifs(){ get "user/replies" ".replies | reverse | $notifs_jq"; } notifs2(){ echo "use mentions instead"; } -mentions(){ getauth "user/mention" ".mentions | reverse | $notifs_jq"; } -home(){ getauth "post/list" ".posts | $posts_jq" "type_=Subscribed"; } +mentions(){ get "user/mention" ".mentions | reverse | $notifs_jq"; } +home(){ get "post/list" ".posts | $posts_jq" "type_=Subscribed"; } #This has to get complex now -.- -comments(){ getauth "post" "(.post_view | $full_post_jq)" "id=$1"; getauth "comment/list" "(.comments | reverse | $comments_jq)" "post_id=$1&sort=New"; } +comments(){ get "post" "(.post_view | $full_post_jq)" "id=$1"; get "comment/list" "(.comments | reverse | $comments_jq)" "post_id=$1&sort=New"; } diff --git a/commands/posts.sh b/commands/posts.sh index c2a9b91..f71ce58 100644 --- a/commands/posts.sh +++ b/commands/posts.sh @@ -1,7 +1,7 @@ #Post hoardan save(){ put "post/save" '{"post_id":'$1',"save":true}'; } unsave(){ put "post/save" '{"post_id":'$1',"save":false}'; } -load(){ getauth "post/list" ".posts | .[] | $short_post_jq" "type_=All&saved_only=true"; } +load(){ get "post/list" ".posts | .[] | $short_post_jq" "type_=All&saved_only=true"; } #Postan 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'"}'; } \ No newline at end of file