add game
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import "server-only";
|
||||
import {
|
||||
atprotoPutRecord,
|
||||
atprotoCreateRecord,
|
||||
atprotoDeleteRecord,
|
||||
atprotoGetRecord,
|
||||
} from "./record";
|
||||
import { z } from "zod";
|
||||
import { DataLayerError } from "../error";
|
||||
import { DID, getPdsUrl } from "./did";
|
||||
|
||||
export const PostCollection = "ai.syui.game";
|
||||
|
||||
export const PostRecord = z.object({
|
||||
account: z.string(),
|
||||
createdAt: z.string(),
|
||||
});
|
||||
|
||||
export type Post = z.infer<typeof PostRecord>;
|
||||
|
||||
type PostInput = {
|
||||
account: string;
|
||||
};
|
||||
|
||||
export async function putPost({ account }: PostInput) {
|
||||
const record = { account, createdAt: new Date().toISOString() };
|
||||
PostRecord.parse(record);
|
||||
|
||||
const result = await atprotoPutRecord({
|
||||
rkey: "self",
|
||||
record,
|
||||
collection: PostCollection,
|
||||
});
|
||||
|
||||
return {
|
||||
rkey: "self",
|
||||
};
|
||||
}
|
||||
|
||||
export async function deletePost(rkey: string) {
|
||||
await atprotoDeleteRecord({
|
||||
rkey,
|
||||
collection: PostCollection,
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPost({ rkey, repo }: { rkey: string; repo: DID }) {
|
||||
const service = await getPdsUrl(repo);
|
||||
|
||||
if (!service) {
|
||||
throw new DataLayerError("Failed to get service url");
|
||||
}
|
||||
|
||||
const { value } = await atprotoGetRecord({
|
||||
serviceEndpoint: service,
|
||||
repo,
|
||||
collection: PostCollection,
|
||||
rkey,
|
||||
});
|
||||
|
||||
return PostRecord.parse(value);
|
||||
}
|
||||
Reference in New Issue
Block a user