Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created December 15, 2024 12:44
Show Gist options
  • Save YonatanKra/1b1261e854a608efeb4fe67f5bd1b1b1 to your computer and use it in GitHub Desktop.
Save YonatanKra/1b1261e854a608efeb4fe67f5bd1b1b1 to your computer and use it in GitHub Desktop.
async function parsePostUri(uri: string, agent: AtpAgent): Promise<{ repo: string; collection: string; rkey: string; } | boolean> {
// Extract handle and post ID
const match = uri.match(/profile\/([^/]+)\/post\/([^/]+)/);
if (!match) {
return false;
}
const [, handle, rkey] = match;
// Get the did
const { data: { did: repo }} = await agent.resolveHandle({handle});
// Use the official bsky app
const collection = 'app.bsky.feed.post';
return {
repo,
collection,
rkey
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment