AT protocol bookmarking platforms in obsidian
at margin 78 lines 1.8 kB view raw
1import type { Client } from "@atcute/client"; 2import type { ActorIdentifier, Nsid } from "@atcute/lexicons"; 3 4export async function getMarginBookmarks(client: Client, repo: string) { 5 return await client.get("com.atproto.repo.listRecords", { 6 params: { 7 repo: repo as ActorIdentifier, 8 collection: "at.margin.bookmark" as Nsid, 9 limit: 100, 10 }, 11 }); 12} 13 14export async function createMarginBookmark( 15 client: Client, 16 repo: string, 17 source: 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: "at.margin.bookmark" as Nsid, 26 record: { 27 $type: "at.margin.bookmark", 28 source, 29 title, 30 description, 31 tags, 32 createdAt: new Date().toISOString(), 33 }, 34 }, 35 }); 36} 37 38export async function getMarginCollections(client: Client, repo: string) { 39 return await client.get("com.atproto.repo.listRecords", { 40 params: { 41 repo: repo as ActorIdentifier, 42 collection: "at.margin.collection" as Nsid, 43 limit: 100, 44 }, 45 }); 46} 47 48export async function getMarginCollectionItems(client: Client, repo: string) { 49 return await client.get("com.atproto.repo.listRecords", { 50 params: { 51 repo: repo as ActorIdentifier, 52 collection: "at.margin.collectionItem" as Nsid, 53 limit: 100, 54 }, 55 }); 56} 57 58export async function createMarginCollection( 59 client: Client, 60 repo: string, 61 name: string, 62 description?: string, 63 icon?: string 64) { 65 return await client.post("com.atproto.repo.createRecord", { 66 input: { 67 repo: repo as ActorIdentifier, 68 collection: "at.margin.collection" as Nsid, 69 record: { 70 $type: "at.margin.collection", 71 name, 72 description, 73 icon, 74 createdAt: new Date().toISOString(), 75 }, 76 }, 77 }); 78}