205 lines
4.5 KiB
Bash
205 lines
4.5 KiB
Bash
function at-env() {
|
|
pds=bsky.social
|
|
plc=plc.directory
|
|
host=https://bsky.social
|
|
handle_syui=syui.ai
|
|
handle_yui=yui.syui.ai
|
|
did_yui=did:plc:4hqjfn7m6n5hno3doamuhgef
|
|
did_syui=did:plc:uqzpqmrjnptsxezjx4xuh2mn
|
|
handle=$handle_yui
|
|
did=$did_yui
|
|
created=2025-04-21T00:00:00.323Z
|
|
at_uri=at://$did_yui/ai.syui.game.user/syui
|
|
docs_uri=https://docs.bsky.app/docs/api
|
|
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/ai/token.json
|
|
if [ -f $f ];then
|
|
host=`cat $f|jq -r ".didDoc.service.[].serviceEndpoint"`
|
|
token=`cat $f|jq -r .accessJwt`
|
|
did=`cat $f|jq -r .did`
|
|
handle=`cat $f|jq -r .handle`
|
|
actor=$did
|
|
fi
|
|
}
|
|
|
|
function at-unset() {
|
|
unset t password token refresh
|
|
}
|
|
|
|
function at-version-env() {
|
|
case $1 in
|
|
bsky)
|
|
tag=$1
|
|
list=( public.api.bsky.app bsky.syu.is )
|
|
;;
|
|
ozone)
|
|
tag=$1
|
|
list=( ozone.bsky.social ozone.syu.is )
|
|
;;
|
|
*)
|
|
tag=pds
|
|
list=( bsky.social syu.is socl.is )
|
|
;;
|
|
esac
|
|
title="atproto $tag version"
|
|
latest=https://raw.githubusercontent.com/bluesky-social/atproto/refs/heads/main/packages/$tag/package.json
|
|
latest=`curl -sL $latest |jq -r .version`
|
|
# bgs=( bsky.network bgs.syu.is )
|
|
# plc=( plc.directory plc.syu.is )
|
|
}
|
|
|
|
function at-version-json() {
|
|
echo "[{\"title\":\"$title\",\"latest\":\"$latest\"},["
|
|
e=${list[@]: -1}
|
|
for i in $list; do
|
|
t=`curl -sL ${i}/xrpc/_health |jq -r .version`
|
|
echo "{\"$i\":\"$t\"}"
|
|
if [ "$e" != "$i" ];then
|
|
echo ,
|
|
fi
|
|
done
|
|
echo "]]"
|
|
}
|
|
|
|
function at-version() {
|
|
at-version-env
|
|
at-version-json|jq .
|
|
}
|
|
|
|
function at-uri() {
|
|
if [ -n "$1" ];then
|
|
at_uri=$1
|
|
fi
|
|
req=/xrpc/com.atproto.repo.getRecord
|
|
url=https://${host}${req}
|
|
did=`echo $at_uri|cut -d / -f 3`
|
|
collection=`echo $at_uri|cut -d / -f 4`
|
|
rkey=`echo $at_uri|cut -d / -f 5`
|
|
curl -sL "$url?repo=$did&collection=$collection&rkey=$rkey"|jq .
|
|
}
|
|
|
|
function at-did() {
|
|
if [ -n "$1" ];then
|
|
handle=$1
|
|
fi
|
|
req=/xrpc/com.atproto.repo.describeRepo
|
|
url=https://${host}${req}
|
|
curl -sL "$url?repo=$handle"|jq .
|
|
}
|
|
|
|
function at-collection() {
|
|
reverse=false
|
|
if [ -n "$1" ];then
|
|
at_uri=$1
|
|
fi
|
|
if [ "$2" = "-r" ];then
|
|
reverse=true
|
|
fi
|
|
req=/xrpc/com.atproto.repo.listRecords
|
|
url=https://${host}${req}
|
|
did=`echo $at_uri|cut -d / -f 3`
|
|
collection=`echo $at_uri|cut -d / -f 4`
|
|
curl -sL "$url?repo=$did&collection=$collection&reverse=$reverse"|jq .
|
|
}
|
|
|
|
function at-docs() {
|
|
for i in $lexicon; do
|
|
req=`echo $i|tr '.' '-'|sed 's/[A-Z]/-&/g'|tr '[A-Z]' '[a-z]'`
|
|
url=$docs_uri/$req
|
|
echo $url
|
|
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
|
|
}
|
|
|
|
function at-refresh() {
|
|
echo $f
|
|
token=`cat $f|jq -r .refreshJwt`
|
|
req=/xrpc/com.atproto.server.refreshSession
|
|
url=${host}${req}
|
|
t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url`
|
|
if echo $t |jq .;then
|
|
echo $t >! $f
|
|
fi
|
|
}
|
|
|
|
function at-cid() {
|
|
did=`at-did $1|jq -r .did`
|
|
cid=$2
|
|
req=/xrpc/com.atproto.sync.getBlob
|
|
url="${host}${req}?did=${did}&cid=${cid}"
|
|
curl -sL $url
|
|
}
|
|
|
|
function at-session() {
|
|
req=/xrpc/com.atproto.server.getSession
|
|
url=${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="${host}${req}?actor=$did"
|
|
curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url|jq .
|
|
}
|
|
|
|
function verify-icon() {
|
|
syuisadmin_handle=ai.syu.is
|
|
syuisadmin_did=did:plc:6qyecktefllvenje24fcxnie
|
|
#rkey=
|
|
col=app.bsky.graph.verification
|
|
handle=syui.syu.is
|
|
subject=did:plc:vzsvtbtbnwn22xjqhcu3vd6y
|
|
displayName=syui
|
|
req=/xrpc/com.atproto.repo.createRecord
|
|
url=${host}${req}
|
|
json="
|
|
{
|
|
\"repo\": \"$syuisadmin_handle\",
|
|
\"did\": \"$syuisadmin_did\",
|
|
\"collection\": \"$col\",
|
|
\"record\": {
|
|
\"subject\": \"$subject\",
|
|
\"handle\": \"$handle\",
|
|
\"displayName\": \"$displayName\",
|
|
\"createdAt\": \"${created}\"
|
|
}
|
|
}"
|
|
|
|
if echo $json|jq . ;then
|
|
t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d $json $url`
|
|
echo $t
|
|
fi
|
|
}
|