AT protocol bookmarking platforms in obsidian
at margin 60 lines 1.4 kB view raw
1import type { Client } from "@atcute/client"; 2import type { ActorIdentifier, Nsid } from "@atcute/lexicons"; 3 4export async function getBookmarks(client: Client, repo: string) { 5 return await client.get("com.atproto.repo.listRecords", { 6 params: { 7 repo: repo as ActorIdentifier, 8 collection: "community.lexicon.bookmarks.bookmark" as Nsid, 9 limit: 100, 10 }, 11 }); 12} 13 14export async function createBookmark( 15 client: Client, 16 repo: string, 17 subject: string, 18 title?: string, 19 description?: string, 20 tags?: string[] 21) { 22 return await client.post("com.atproto.repo.createRecord", { 23 input: { 24 repo: repo as ActorIdentifier, 25 collection: "community.lexicon.bookmarks.bookmark" as Nsid, 26 record: { 27 $type: "community.lexicon.bookmarks.bookmark", 28 subject, 29 title, 30 description, 31 tags, 32 createdAt: new Date().toISOString(), 33 }, 34 }, 35 }); 36} 37 38export async function getTags(client: Client, repo: string) { 39 return await client.get("com.atproto.repo.listRecords", { 40 params: { 41 repo: repo as ActorIdentifier, 42 collection: "com.kipclip.tag" as Nsid, 43 limit: 100, 44 }, 45 }); 46} 47 48export async function createTag(client: Client, repo: string, value: string) { 49 return await client.post("com.atproto.repo.createRecord", { 50 input: { 51 repo: repo as ActorIdentifier, 52 collection: "com.kipclip.tag" as Nsid, 53 record: { 54 $type: "com.kipclip.tag", 55 value, 56 createdAt: new Date().toISOString(), 57 }, 58 }, 59 }); 60}