88 BLUESKY_URL_EXTRACT_REGEX ,
99} from '#shared/utils/constants'
1010import { type BlueskyOEmbedResponse , BlueskyOEmbedRequestSchema } from '#shared/schemas/atproto'
11+ import { Client } from '@atproto/lex'
12+ import * as com from '#shared/types/lexicons/com'
1113
1214export default defineCachedEventHandler (
1315 async ( event ) : Promise < BlueskyOEmbedResponse > => {
@@ -21,15 +23,14 @@ export default defineCachedEventHandler(
2123 * If the schema passes, this regex is mathematically guaranteed to match and contain both capture groups.
2224 * Match returns ["profile/danielroe.dev/post/123", "danielroe.dev", "123"] — only want the two capture groups, the full match string is discarded.
2325 */
24- const [ , handle , postId ] = url . match ( BLUESKY_URL_EXTRACT_REGEX ) ! as [ string , string , string ]
26+ const [ , handle , postId ] = url . match ( BLUESKY_URL_EXTRACT_REGEX ) ! as [
27+ string ,
28+ `${string } .${string } `,
29+ string ,
30+ ]
2531
26- // INFO: Resolve handle to DID using Bluesky's public API
27- const { did } = await $fetch < { did : string } > (
28- `${ BLUESKY_API } com.atproto.identity.resolveHandle` ,
29- {
30- query : { handle } ,
31- } ,
32- )
32+ const client = new Client ( { service : BLUESKY_API } )
33+ const { did } = await client . call ( com . atproto . identity . resolveHandle , { handle } )
3334
3435 // INFO: Construct the embed URL with the DID
3536 const embedUrl = `${ BLUESKY_EMBED_BASE_ROUTE } /embed/${ did } /app.bsky.feed.post/${ postId } ?colorMode=${ colorMode } `
0 commit comments