/** * parse bluesky URLs into AT-URI components * * supports: * https://bsky.app/profile/{handle}/post/{rkey} * at://{did}/{collection}/{rkey} */ const BSKY_URL_RE = /^https?:\/\/bsky\.app\/profile\/([^/]+)\/post\/([a-z2-7]+)$/; const AT_URI_RE = /^at:\/\/(did:[^/]+)\/(app\.bsky\.feed\.post)\/([a-z2-7]+)$/; export function parseBlueskyUrl(input) { const trimmed = input.trim(); // try AT-URI first const atMatch = trimmed.match(AT_URI_RE); if (atMatch) { return { did: atMatch[1], collection: atMatch[2], rkey: atMatch[3] }; } // try bsky.app URL const urlMatch = trimmed.match(BSKY_URL_RE); if (urlMatch) { return { handle: urlMatch[1], rkey: urlMatch[2] }; } return null; } export function makeAtUri(did, collection, rkey) { return `at://${did}/${collection}/${rkey}`; }