Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142import { AtpAgent } from "@atproto/api"import type { Note } from "~/api/note.type"
let serviceEndpoint: string | null = nullconst did = "did:plc:4m3kouplb7s7xozjd3whinvl"
export const getServiceEndpoint = async () => { if (serviceEndpoint) { return serviceEndpoint } const response = await fetch(`https://plc.directory/${did}`) const { service: [{ serviceEndpoint: endpoint }], } = await response.json()
if (!endpoint) { return null }
serviceEndpoint = endpoint
return endpoint}
export const fetchNotes = async (): Promise<Note[]> => { const endpoint = await getServiceEndpoint() const agent = new AtpAgent({ service: endpoint })
const { data: { records }, } = await agent.com.atproto.repo.listRecords({ repo: did, collection: "site.standard.document", limit: 50, })
const notes = (records || []).map((record) => record.value as Note) return notes.sort((a, b) => a.publishedAt < b.publishedAt ? 1 : a.publishedAt > b.publishedAt ? -1 : 0, )}