Leaflet Blog in Deno Fresh
at main 1.1 kB view raw
1import { bsky } from "./bsky.ts"; 2import { env } from "./env.ts"; 3 4import { type ActorIdentifier } from "npm:@atcute/lexicons"; 5import { type ComAtprotoRepoListRecords } from "npm:@atcute/atproto"; 6import { type PubLeafletDocument } from "npm:@atcute/leaflet"; 7 8export async function getPosts() { 9 const posts = await bsky.get("com.atproto.repo.listRecords", { 10 params: { 11 repo: env.NEXT_PUBLIC_BSKY_DID as ActorIdentifier, 12 collection: "pub.leaflet.document", 13 // todo: pagination 14 }, 15 }); 16 17 if ("error" in posts.data) { 18 throw new Error(posts.data.error); 19 } 20 21 return posts.data.records as (ComAtprotoRepoListRecords.Record & { 22 value: PubLeafletDocument.Main; 23 })[]; 24} 25 26export async function getPost(rkey: string) { 27 const post = await bsky.get("com.atproto.repo.getRecord", { 28 params: { 29 repo: env.NEXT_PUBLIC_BSKY_DID as ActorIdentifier, 30 rkey: rkey, 31 collection: "pub.leaflet.document", 32 }, 33 }); 34 35 return post.data as ComAtprotoRepoListRecords.Record & { 36 value: PubLeafletDocument.Main; 37 }; 38}