fix
This commit is contained in:
parent
e7471b20e4
commit
5bdf1c92e6
82
at.zsh
Executable file
82
at.zsh
Executable file
@ -0,0 +1,82 @@
|
||||
#!/bin/zsh
|
||||
|
||||
help=(
|
||||
at.zsh d handle
|
||||
at.zsh u at-uri
|
||||
at.zsh c at-uri -r
|
||||
)
|
||||
host=(
|
||||
bsky.social
|
||||
public.api.bsky.app
|
||||
plc.directory
|
||||
)
|
||||
lexicon=(
|
||||
xrpc/com.atproto.repo.describeRepo
|
||||
xrpc/com.atproto.repo.getRecord
|
||||
xrpc/com.atproto.repo.listRecords
|
||||
xrpc/com.atproto.identity.resolveHandle
|
||||
)
|
||||
|
||||
function at-env(){
|
||||
host=bsky.social
|
||||
at_uri=at://did:plc:4hqjfn7m6n5hno3doamuhgef/ai.syui.game.user/syui
|
||||
handle=yui.syui.ai
|
||||
did=`echo $at_uri|cut -d / -f 3`
|
||||
collection=`echo $at_uri|cut -d / -f 4`
|
||||
rkey=`echo $at_uri|cut -d / -f 5`
|
||||
}
|
||||
|
||||
function at-uri-search(){
|
||||
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-search(){
|
||||
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-search(){
|
||||
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 .
|
||||
}
|
||||
|
||||
at-env
|
||||
case $1 in
|
||||
uri|u)
|
||||
at-uri-search $2
|
||||
;;
|
||||
did|d)
|
||||
at-did-search $2
|
||||
;;
|
||||
collection|c)
|
||||
at-collection-search $2 $3
|
||||
;;
|
||||
*)
|
||||
echo "${help[@]}"
|
||||
echo "${host[@]}"
|
||||
echo "${lexicon[@]}"
|
||||
;;
|
||||
esac
|
||||
|
@ -0,0 +1,50 @@
|
||||
import "server-only";
|
||||
import { z } from "zod";
|
||||
import { ensureUser } from "../user";
|
||||
import { DataLayerError } from "../error";
|
||||
import { fetchAuthenticatedAtproto } from "@/lib/auth";
|
||||
import { AtUri } from "./uri";
|
||||
|
||||
const PutRecordResponse = z.object({
|
||||
uri: AtUri,
|
||||
cid: z.string(),
|
||||
});
|
||||
|
||||
type PutRecordInput = {
|
||||
rkey?: string;
|
||||
record: unknown;
|
||||
collection: string;
|
||||
};
|
||||
|
||||
export async function atprotoPutRecord({
|
||||
rkey,
|
||||
record,
|
||||
collection,
|
||||
}: PutRecordInput) {
|
||||
const user = await ensureUser();
|
||||
const pdsUrl = new URL(user.pdsUrl);
|
||||
pdsUrl.pathname = "/xrpc/com.atproto.repo.putRecord";
|
||||
|
||||
const response = await fetchAuthenticatedAtproto(pdsUrl.toString(), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
rkey: rkey || "self",
|
||||
repo: user.did,
|
||||
collection,
|
||||
validate: false,
|
||||
record: record,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new DataLayerError(`Failed to create record ${response.status}`, {
|
||||
cause: response,
|
||||
});
|
||||
}
|
||||
|
||||
return PutRecordResponse.parse(await response.json());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user