ai/at
ai/at
1
0
This commit is contained in:
syui 2024-11-28 05:25:43 +09:00
parent 1512a1452f
commit d532d51ab9
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56

98
at.zsh
View File

@ -1,12 +1,16 @@
#!/bin/zsh #!/bin/zsh
help=( help=(
at.zsh v
at.zsh d handle at.zsh d handle
at.zsh u at-uri at.zsh u at-uri
at.zsh c at-uri -r at.zsh c at-uri -r
at.zsh docs at.zsh docs
at.zsh l handle password at.zsh l handle password
at.zsh r at.zsh r
at.zsh s
at.zsh cid handle cid
at.zsh pro
) )
host=( host=(
bsky.social bsky.social
@ -14,13 +18,26 @@ host=(
plc.directory plc.directory
) )
lexicon=( lexicon=(
# https://github.com/bluesky-social/atproto/tree/main/lexicons
com.atproto.repo.describeRepo com.atproto.repo.describeRepo
com.atproto.repo.getRecord com.atproto.repo.getRecord
com.atproto.repo.listRecords com.atproto.repo.listRecords
com.atproto.identity.resolveHandle com.atproto.identity.resolveHandle
com.atproto.server.createSession com.atproto.server.createSession
com.atproto.server.refreshSession com.atproto.server.refreshSession
com.atproto.server.getSession
com.atproto.sync.getBlob
app.bsky.actor.getProfile
) )
github=(
https://github.com/bluesky-social/atproto
https://github.com/bluesky-social/social-app
https://github.com/bluesky-social/feed-generator
https://github.com/bluesky-social/jetstream
https://github.com/bluesky-social/indigo
https://github.com/did-method-plc/did-method-plc
)
tag=( at bsky bsync pds bgs plc ozone feed jetstream social-app oauth )
function at-env() { function at-env() {
host=bsky.social host=bsky.social
@ -32,9 +49,23 @@ function at-env() {
rkey=`echo $at_uri|cut -d / -f 5` rkey=`echo $at_uri|cut -d / -f 5`
d=${0:a:h} d=${0:a:h}
f=~/.config/.at-zsh.json f=~/.config/.at-zsh.json
if [ -f $f ];then
token=`cat $f|jq -r .accessJwt`
did=`cat $f|jq -r .did`
handle=`cat $f|jq -r .handle`
actor=$did
fi
} }
function at-uri-search() { function at-unset() {
unset t password token refresh
}
function at-version() {
curl -sL ${host}/xrpc/_health |jq .
}
function at-uri() {
if [ -n "$1" ];then if [ -n "$1" ];then
at_uri=$1 at_uri=$1
fi fi
@ -46,7 +77,7 @@ function at-uri-search() {
curl -sL "$url?repo=$did&collection=$collection&rkey=$rkey"|jq . curl -sL "$url?repo=$did&collection=$collection&rkey=$rkey"|jq .
} }
function at-did-search() { function at-did() {
if [ -n "$1" ];then if [ -n "$1" ];then
handle=$1 handle=$1
fi fi
@ -55,7 +86,7 @@ function at-did-search() {
curl -sL "$url?repo=$handle"|jq . curl -sL "$url?repo=$handle"|jq .
} }
function at-collection-search() { function at-collection() {
reverse=false reverse=false
if [ -n "$1" ];then if [ -n "$1" ];then
at_uri=$1 at_uri=$1
@ -70,7 +101,6 @@ function at-collection-search() {
curl -sL "$url?repo=$did&collection=$collection&reverse=$reverse"|jq . curl -sL "$url?repo=$did&collection=$collection&reverse=$reverse"|jq .
} }
function at-docs() { function at-docs() {
for i in $lexicon; do for i in $lexicon; do
req=`echo $i|tr '.' '-'|sed 's/[A-Z]/-&/g'|tr '[A-Z]' '[a-z]'` req=`echo $i|tr '.' '-'|sed 's/[A-Z]/-&/g'|tr '[A-Z]' '[a-z]'`
@ -97,53 +127,87 @@ function at-login() {
if echo $t |jq .;then if echo $t |jq .;then
echo $t >! $f echo $t >! $f
fi fi
unset t password
} }
function at-refresh() { function at-refresh() {
echo $f echo $f
token=`cat $f|jq -r .accessJwt` token=`cat $f|jq -r .refreshJwt`
refresh=`cat $f|jq -r .refreshJwt`
req=/xrpc/com.atproto.server.refreshSession req=/xrpc/com.atproto.server.refreshSession
url=https://${host}${req} url=https://${host}${req}
t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url` t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url`
if echo $t |jq .;then if echo $t |jq .;then
echo $t >! $f echo $t >! $f
fi fi
unset t token refresh
} }
function at-version() { function at-cid() {
curl -sL ${host}/xrpc/_health |jq . did=`at-did $1|jq -r .did`
cid=$2
req=/xrpc/com.atproto.sync.getBlob
url="https://${host}${req}?did=${did}&cid=${cid}"
curl -sL $url
}
function at-session() {
req=/xrpc/com.atproto.server.getSession
url=https://${host}${req}
t=`curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url`
if ! echo $t |jq .;then
echo refresh
t=`at-refresh`
fi
}
function at-profile() {
if [ ! -f $f ];then
echo login
exit
else
t=`at-session`
fi
req=/xrpc/app.bsky.actor.getProfile
url="https://${host}${req}?actor=$did"
curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url|jq .
} }
at-env at-env
case $1 in case $1 in
version|v)
at-version
;;
uri|u) uri|u)
at-uri-search $2 at-uri $2
;; ;;
did|d) did|d)
at-did-search $2 at-did $2
;; ;;
collection|c) collection|c)
at-collection-search $2 $3 at-collection $2 $3
;; ;;
at-docs|docs) at-docs|docs)
at-docs at-docs
;; ;;
cid)
at-cid $2 $3
;;
login|l) login|l)
at-login $2 $3 at-login $2 $3
;; ;;
refresh|r) refresh|r)
at-refresh at-refresh
;; ;;
version|v) session|s)
at-version at-session
;;
profile|pro)
at-profile
;; ;;
*) *)
echo "${help[@]}" echo "${help[@]}"
echo "${host[@]}" echo "${host[@]}"
echo "${lexicon[@]}" echo "${lexicon[@]}"
echo "${github[@]}"
echo "${tag[@]}"
;; ;;
esac esac
at-unset