add json
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
token.json
|
97
bin/verse.zsh
Executable file
97
bin/verse.zsh
Executable file
@@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
function at_env_arg() {
|
||||||
|
handle=syui.syui.ai
|
||||||
|
col=ai.syui.verse.user
|
||||||
|
rkey=self
|
||||||
|
host=syu.is
|
||||||
|
}
|
||||||
|
|
||||||
|
function at_env() {
|
||||||
|
d=${0:a:h}
|
||||||
|
dd=${0:a:h:h}
|
||||||
|
pds=$host
|
||||||
|
f=$d/token.json
|
||||||
|
if [ ! -f $f ];then
|
||||||
|
echo password
|
||||||
|
read password
|
||||||
|
else
|
||||||
|
did=`cat $f|jq -r .did`
|
||||||
|
access=`cat $f|jq -r .accessJwt`
|
||||||
|
refresh=`cat $f|jq -r .refreshJwt`
|
||||||
|
fi
|
||||||
|
j_verse=`cat $dd/json/verse.json`
|
||||||
|
j_user=`cat $dd/json/user.json`
|
||||||
|
|
||||||
|
case $col in
|
||||||
|
ai.syui.verse)
|
||||||
|
j=${j_verse}
|
||||||
|
;;
|
||||||
|
ai.syui.verse.user)
|
||||||
|
j=${j_user}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if ! echo $j|jq .;then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
if [ -n "`which gdate`" ];then
|
||||||
|
date=`gdate --iso-8601=seconds`
|
||||||
|
else
|
||||||
|
date=`date --iso-8601=seconds`
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function at_create_session(){
|
||||||
|
if [ ! -f $f ];then
|
||||||
|
req=com.atproto.server.createSession
|
||||||
|
url=https://$pds/xrpc/$req
|
||||||
|
curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$password\"}" $url >! $f
|
||||||
|
did=`cat $f|jq -r .did`
|
||||||
|
access=`cat $f|jq -r .accessJwt`
|
||||||
|
refresh=`cat $f|jq -r .refreshJwt`
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function at_refresh_session(){
|
||||||
|
req=com.atproto.server.refreshSession
|
||||||
|
url=https://${pds}/xrpc/$req
|
||||||
|
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url >! $f
|
||||||
|
did=`cat $f|jq -r .did`
|
||||||
|
access=`cat $f|jq -r .accessJwt`
|
||||||
|
refresh=`cat $f|jq -r .refreshJwt`
|
||||||
|
}
|
||||||
|
|
||||||
|
function at_put_record() {
|
||||||
|
req=com.atproto.repo.putRecord
|
||||||
|
url=https://$pds/xrpc/$req
|
||||||
|
|
||||||
|
# jqでrecordを構築
|
||||||
|
record=$(echo "$j" | jq ". + {\"createdAt\": \"$date\", \"updatedAt\": \"$date\"}")
|
||||||
|
|
||||||
|
json=$(jq -n \
|
||||||
|
--arg repo "$handle" \
|
||||||
|
--arg did "$did" \
|
||||||
|
--arg collection "$col" \
|
||||||
|
--arg rkey "$rkey" \
|
||||||
|
--argjson record "$record" \
|
||||||
|
'{
|
||||||
|
"repo": $repo,
|
||||||
|
"did": $did,
|
||||||
|
"collection": $collection,
|
||||||
|
"rkey": $rkey,
|
||||||
|
"record": $record
|
||||||
|
}')
|
||||||
|
|
||||||
|
echo $json
|
||||||
|
if echo $json|jq . ;then
|
||||||
|
t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $access" -d "$json" $url`
|
||||||
|
echo $t|jq .
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
at_env_arg
|
||||||
|
at_env
|
||||||
|
at_create_session
|
||||||
|
at_refresh_session
|
||||||
|
at_put_record
|
14
json/user.json
Normal file
14
json/user.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"character": [
|
||||||
|
{ "id": 0, "cp": 100, "unique": true },
|
||||||
|
{ "id": 1, "cp": 100 , "unique": false }
|
||||||
|
],
|
||||||
|
"item": [
|
||||||
|
{ "id": 0, "cp": 0 },
|
||||||
|
{ "id": 1, "cp": 0 }
|
||||||
|
],
|
||||||
|
"card": [
|
||||||
|
{ "id": 0, "cp": 0 },
|
||||||
|
{ "id": 1, "cp": 0 }
|
||||||
|
]
|
||||||
|
}
|
23
json/verse.json
Normal file
23
json/verse.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"system": [
|
||||||
|
{
|
||||||
|
"at": "account",
|
||||||
|
"ai": "ability",
|
||||||
|
"yui": "unique",
|
||||||
|
"world": "planet"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"yui": {
|
||||||
|
"character": [
|
||||||
|
{"id": 0, "name": "ai", "ability": "ai"},
|
||||||
|
{"id": 1, "name": "shin", "ability": "atom"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ai": {
|
||||||
|
"ability": [
|
||||||
|
{ "id": 0, "name": "ai", "multiplier": { "ai": 2.0, "yui": 1.5, "atom": 1.2 } },
|
||||||
|
{ "id": 1, "name": "yui", "multiplier": { "ai": 2.0, "yui": 0.0, "atom": 0.0 } },
|
||||||
|
{ "id": 2, "name": "atom", "multiplier": { "ai": 0.0, "yui": 0.0, "atom": 0.0 } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user