CLI tool to sync your Markdown to Leaflet
leafletpub atproto cli markdown
30
fork

Configure Feed

Select the types of activity you want to include in your feed.

Resolve user's PDS and DID with Slingshot

SharpMars 51d78354 4d03fb2b

+17 -7
+17 -7
src/commands/sync-cmd.ts
··· 21 21 import { consola } from "consola"; 22 22 import { exists, readJson, loadConfig } from "../utils.ts"; 23 23 import { parse } from "yaml"; 24 + import type { AtprotoDid, Handle } from "@atcute/lexicons/syntax"; 24 25 25 26 export const syncCmd = defineCommand({ 26 27 async run({ cmd, args }) { ··· 32 33 33 34 const mapPath = join(process.cwd(), "/leaflet-md.map.json"); 34 35 35 - const handler = new CredentialManager({ service: "https://bsky.social" }); 36 - const client = new Client({ handler: handler }); 37 - 38 36 if (!process.env.BSKY_HANDLE) { 39 37 throw new Error("BSKY_HANDLE not provided in .env"); 40 38 } 41 39 40 + const miniDocRes = await fetch( 41 + `https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=${encodeURIComponent(process.env.BSKY_HANDLE)}` 42 + ); 43 + if (!miniDocRes.ok) 44 + throw new Error( 45 + `Slingshot status: ${miniDocRes.status} - ${miniDocRes.statusText}\n${((await miniDocRes.json()) as any).message}` 46 + ); 47 + const miniDoc = (await miniDocRes.json()) as { did: AtprotoDid; handle: Handle; pds: string; signing_key: string }; 48 + 49 + const handler = new CredentialManager({ service: miniDoc.pds }); 50 + const client = new Client({ handler: handler }); 51 + 42 52 if (!process.env.BSKY_PASSW) { 43 53 throw new Error("BSKY_PASSW not provided in .env"); 44 54 } ··· 48 58 const publications = new Map<RecordKey, string>(); 49 59 const uploadedDocuments = new Map<RecordKey, { cid: string; publishedAt?: string }>(); 50 60 51 - const carReq = await fetch(`${handler.session!.pdsUri!}/xrpc/com.atproto.sync.getRepo?did=${handler.session!.did}`); 61 + const carReq = await fetch(`${miniDoc.pds}/xrpc/com.atproto.sync.getRepo?did=${miniDoc.did}`); 52 62 await using repo = RepoReader.fromStream(carReq.body!); 53 63 54 64 for await (const entry of repo) { ··· 76 86 } else { 77 87 if (publications.size > 0) { 78 88 const publication = publications.entries().next().value!; 79 - publicationUri = `at://${handler.session!.did}/pub.leaflet.publication/${publication[0]}`; 89 + publicationUri = `at://${miniDoc.did}/pub.leaflet.publication/${publication[0]}`; 80 90 publicationName = publication[1]; 81 91 } else { 82 92 throw new Error("Could not find any publications in your repo."); ··· 267 277 uploadDate ??= new Date(Date.now()).toISOString(); 268 278 269 279 const doc = generateDoc( 270 - handler.session!.did, 280 + miniDoc.did, 271 281 publicationUri, 272 282 [...prependBlocks, ...generateBlocks(ast.children, uploadedImages), ...appendBlocks], 273 283 title, ··· 287 297 const res = await client.post("com.atproto.repo.putRecord", { 288 298 input: { 289 299 collection: "pub.leaflet.document", 290 - repo: handler.session!.did, 300 + repo: miniDoc.did, 291 301 rkey: tid, 292 302 record: doc, 293 303 },