From f58ad9022d90cb63715bbf18f26bca08c367672a Mon Sep 17 00:00:00 2001 From: syui Date: Thu, 28 Nov 2024 04:41:09 +0900 Subject: [PATCH] fix --- at.zsh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/at.zsh b/at.zsh index f10906a..cc39891 100755 --- a/at.zsh +++ b/at.zsh @@ -16,6 +16,8 @@ lexicon=( com.atproto.repo.getRecord com.atproto.repo.listRecords com.atproto.identity.resolveHandle + com.atproto.server.createSession + com.atproto.server.refreshSession ) function at-env(){ @@ -26,6 +28,8 @@ function at-env(){ did=`echo $at_uri|cut -d / -f 3` collection=`echo $at_uri|cut -d / -f 4` rkey=`echo $at_uri|cut -d / -f 5` + d=${0:a:h} + f=~/.config/.at-zsh.json } function at-uri-search(){ @@ -73,6 +77,40 @@ for i in $lexicon; do done } +function at-login(){ + if [ -z "$1" ] || [ -z "$2" ];then + echo handle password + exit + fi + handle=$1 + password=$2 + echo $password + json="{\"identifier\":\"$handle\",\"password\":\"$password\"}" + req=/xrpc/com.atproto.server.createSession + url=https://${host}${req} + if [ ! -d ~/.config ];then + mkdir -p ~/.config + fi + t=`curl -sL -X POST -H "Content-Type: application/json" -d $json $url` + if echo $t |jq .;then + echo $t >! $f + fi + unset t password +} + +function at-refresh(){ + echo $f + token=`cat $f|jq -r .accessJwt` + refresh=`cat $f|jq -r .refreshJwt` + req=/xrpc/com.atproto.server.refreshSession + url=https://${host}${req} + t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url` + if echo $t |jq .;then + echo $t >! $f + fi + unset t token refresh +} + at-env case $1 in uri|u) @@ -87,6 +125,12 @@ case $1 in at-docs|docs) at-docs ;; + login|l) + at-login $2 $3 + ;; + refresh|r) + at-refresh + ;; *) echo "${help[@]}" echo "${host[@]}"