fix
This commit is contained in:
parent
e7471b20e4
commit
fb987a6f73
@ -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