Page:
curl
Clone
9
curl
syui edited this page 2024-11-27 19:47:39 +00:00
see : https://git.syui.ai/ai/at/src/branch/main/at.zsh
version
$ curl -sL syu.is/xrpc/_health
did
$ curl -sL "syu.is/xrpc/com.atproto.repo.describeRepo?repo=ai.syu.is" |jq -r .did
$ curl -sL plc.syu.is/did:plc:6qyecktefllvenje24fcxnie
timeline
$ curl -sL "syu.is/xrpc/com.atproto.repo.listRecords?repo=ai.syu.is&collection=app.bsky.feed.post&reverse=true&limit=1"
at-uri
#!/bin/zsh
function at-uri-search(){
if [ -z "$1" ];then
# https://at.syu.is/at/did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.game.user/syui
at_uri=at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.game.user/syui
else
at_uri=$1
fi
host=bsky.social
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 .
}
at-uri-search $1
invite code
host=syu.is
admin_password=xxx
url=https://${host}/xrpc/com.atproto.server.createInviteCode
json="{\"useCount\":1}"
curl -X POST -u admin:${admin_password} -H "Content-Type: application/json" -d "$json" -sL $url
create account
host=syu.is
url=https://${host}/xrpc/com.atproto.server.createAccount
json="{\"email\": \"$email\", \"handle\": \"$handle\", \"password\": \"$password\"}"
curl -X POST -H "Content-Type: application/json" -d $json -sL $url
login
# session
host=syu.is
handle=ai.syu.is
password=xxx
url=https://${host}/xrpc/com.atproto.server.createSession
curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$password\"}" $url
# refresh
j=`!!`
token=`echo $j|jq -r .accessJwt`
refresh=`echo $j|jq -r .refreshJwt`
url=https://${host}/xrpc/com.atproto.server.refreshSession
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url
feed
at://did:plc:6qyecktefllvenje24fcxnie/app.bsky.feed.generator/cmd
- https://api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd
- https://feed.syu.is/xrpc/app.bsky.feed.getFeedSkeleton?feed=at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd
- https://desc.syu.is/xrpc/app.bsky.feed.getFeedSkeleton?feed=at://did:plc:6qyecktefllvenje24fcxnie/app.bsky.feed.generator/cmd
# https://docs.bsky.app/docs/api/app-bsky-feed-get-feed
token=`cat ~/.config/ai/token.json|jq -r .accessJwt`
url=at://did:plc:6qyecktefllvenje24fcxnie/app.bsky.feed.generator/cmd
curl -sL "https://syu.is/xrpc/app.bsky.feed.getFeed?feed=$url" -H "Authorization: Bearer $token"
no-authorization
https://docs.bsky.app/docs/api/com-atproto-repo-describe-repo
- /xrpc/com.atproto.repo.describeRepo
- /xrpc/com.atproto.identity.resolveHandle
- /xrpc/com.atproto.repo.listRecords
- /xrpc/com.atproto.repo.getRecord
handle=yui.syui.ai
host=bsky.social
api=$host/xrpc
plc=plc.directory
url=$api/com.atproto.repo.describeRepo
curl -sL ${host}/xrpc/_health
d=`curl -sL "${url}?repo=$handle"`
echo $d
did=`echo $d|jq -r .did`
echo $did
collection=app.bsky.feed.post
url=$api/com.atproto.repo.listRecords
timed=`curl -sL "${url}?repo=$handle&collection=$collection&reverse=true&limit=1"|jq -r ".[]|.[0]?|.value.createdAt"`
cid=`curl -sL "${url}?repo=$handle&collection=$collection&reverse=true&limit=1"|jq -r ".[]|.[0]?|.cid"`
uri=`curl -sL "${url}?repo=$handle&collection=$collection&reverse=true&limit=1"|jq -r ".[]|.[0]?|.uri"`
rkey=`echo $uri|cut -d / -f 5`
url=$api/com.atproto.repo.getRecord
curl -sL "$url?repo=$did&collection=$collection&rkey=$rkey"|jq .
uri=at://did:plc:vjug55kidv6sye7ykr5faxxn/app.bsky.feed.post/3jzn6g7ixgq2y
cid=bafyreiey2tt4dhvuvr7tofatdverqrxmscnnus2uyfcmkacn2fov3vb4wa
did=did:plc:vjug55kidv6sye7ykr5faxxn
rkey=3jzn6g7ixgq2y
url=$api/com.atproto.repo.getRecord
curl -sL "$url?repo=$did&collection=$collection&rkey=$rkey&cid="|jq .
handle=yui.syui.ai
curl -sL "https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=$handle"
{"did":"did:plc:4hqjfn7m6n5hno3doamuhgef"}
did=did:plc:4hqjfn7m6n5hno3doamuhgef
curl -sL https://plc.directory/$did | jq -r ".alsoKnownAs.[]"
at://yui.syui.ai
login
# session
host=bsky.social
handle=syui.bsky.social
pass=xxx
url=https://$host/xrpc/com.atproto.server.createSession
curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" $url
# refresh
j=`!!`
token=`echo $j|jq -r .accessJwt`
refresh=`echo $j|jq -r .refreshJwt`
url=https://$host/xrpc/com.atproto.server.refreshSession
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url
jq
ここではaiosにインストールされているjq, daselのexample
をまとめます。
null
id:3
のname:null
を除外して表示
[
{
"id": 1,
"name": "aios",
"display": "ai os"
},
{
"id": 2,
"name": "archlinux",
"display": "Arch Linux"
},
{
"id": 3,
"display": "Linux Kernel"
}
]
$ echo $json|jq -r ".[]|{name, display}|select(.name | length > 0)|.name,.display"
aios
ai os
archlinux
Arch Linux
$ echo $json|jq -r ".[]|.name // empty"
aios
archlinux
dasel
$ cat ~/.config/ai/token.toml|dasel -r toml host
'syu.is'
feed
feed = at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd
# https://docs.bsky.app/docs/api/app-bsky-feed-get-feed
token=`cat ~/.config/ai/token.json|jq -r .accessJwt`
url=at://did:plc:4hqjfn7m6n5hno3doamuhgef/app.bsky.feed.generator/cmd
curl -sL "https://public.api.bsky.app/xrpc/app.bsky.feed.getFeed?feed=$url" -H "Authorization: Bearer $token"
record
col=ai.syui.game.user
req=com.atproto.repo.putRecord
# "required": ["repo", "collection", "rkey", "record"]
req=com.atproto.repo.createRecord
url=https://$host/xrpc/$req
json='
{
"repo": "yui.syui.ai",
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"collection": "ai.syui.game.user",
"rkey": "3laieqxtlnp2l",
"record": {
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"aiten": 0,
"charactor": {
"ai": {
"hp": 0
}
},
"createdAt": "2024-11-09T12:46:36+09:00"
}
}'
if echo $json|jq . ;then
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token_yui" -d $json $url
read rkey
fi
# recordの書き換え
# rkey=3laieqxtlnp2l
req=com.atproto.repo.putRecord
url=https://$host/xrpc/$req
json='
{
"repo": "yui.syui.ai",
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"collection": "ai.syui.game.user",
"rkey": "3laieqxtlnp2l",
"record": {
"did": "did:plc:4hqjfn7m6n5hno3doamuhgef",
"aiten": 1,
"charactor": {
"ai": {
"hp": 1
}
},
"createdAt": "2024-11-09T12:46:36+09:00"
}
}'
if echo $json|jq . ;then
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token_yui" -d $json $url
#curl -sL -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token_yui" -d $json $url
fi
lexicon
[user]oauth --> [yui]ai.syui.game.user --> [user]ai.syui.game
{
"lexicon": 1,
"id": "ai.syui.game.user",
"defs": {
"main": {
"type": "record",
"key": "tid",
"description": "Record containing a game user.",
"input": {
"encoding": "application/json",
"record": {
"type": "object",
"required": [
"did",
"createdAt"
],
"properties": {
"aiten": {
"type": "integer",
"default": 0
},
"did": {
"type": "string"
},
"charactor": {
"type": "object",
"enum": [
"ai",
"test"
],
"properties": {
"ai": {
"type": "object",
"properties": {
"lv": {
"type": "integer",
"minimum": 1,
"maximum": 7,
"default": 1
},
"exp": {
"type": "integer"
},
"hp": {
"type": "integer",
"maximum": 255,
"default": 0
},
"attach": {
"type": "integer",
"minimum": 1,
"maximum": 255,
"default": 1
},
"critical": {
"type": "integer",
"minimum": 0,
"maximum": 255,
"default": 0
},
"critical_d": {
"type": "integer",
"minimum": 0,
"maximum": 255,
"default": 0
}
}
}
}
},
"createdAt": {
"type": "string",
"format": "datetime",
"description": "Client-declared timestamp when this post was originally created."
},
"updatedAt": {
"type": "string",
"format": "datetime"
}
}
}
}
}
}
}