Skip to content

Commit b316bad

Browse files
committed
fix: use typed ATproto client when fetching bsky embeds
The oembed endpoint used a raw fetch and is missing the `/xrpc` path prefix. This causes a 502 error when trying to fetch embeds. We can use the typed client to be consistent with author-profiles and other atproto api routes. And means we don't need to specify the /xrpc path in the fetch.
1 parent 6eb0317 commit b316bad

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

lexicons.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"app.bsky.feed.getPostThread",
1111
"app.bsky.feed.getPosts",
1212
"app.bsky.feed.post",
13+
"com.atproto.identity.resolveHandle",
1314
"com.bad-example.identity.resolveMiniDoc",
1415
"site.standard.document"
1516
],
@@ -98,6 +99,10 @@
9899
"uri": "at://did:plc:4v4y5r3lwsbtmsxhile2ljac/com.atproto.lexicon.schema/app.bsky.richtext.facet",
99100
"cid": "bafyreidg56eo7zynf6ihz4xb627vwoqf5idnevkmwp7sxc4tijg6xngbu4"
100101
},
102+
"com.atproto.identity.resolveHandle": {
103+
"uri": "at://did:plc:6msi3pj7krzih5qxqtryxlzw/com.atproto.lexicon.schema/com.atproto.identity.resolveHandle",
104+
"cid": "bafyreigckmqtt3jrtzd7tvigjatnz6ajqyafs26h5pwcudwag2anedxnmu"
105+
},
101106
"com.atproto.label.defs": {
102107
"uri": "at://did:plc:6msi3pj7krzih5qxqtryxlzw/com.atproto.lexicon.schema/com.atproto.label.defs",
103108
"cid": "bafyreig4hmnb2xkecyg4aaqfhr2rrcxxb3gsr4xks4rqb7rscrycalbrji"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"id": "com.atproto.identity.resolveHandle",
3+
"defs": {
4+
"main": {
5+
"type": "query",
6+
"errors": [
7+
{
8+
"name": "HandleNotFound",
9+
"description": "The resolution process confirmed that the handle does not resolve to any DID."
10+
}
11+
],
12+
"output": {
13+
"schema": {
14+
"type": "object",
15+
"required": ["did"],
16+
"properties": {
17+
"did": {
18+
"type": "string",
19+
"format": "did"
20+
}
21+
}
22+
},
23+
"encoding": "application/json"
24+
},
25+
"parameters": {
26+
"type": "params",
27+
"required": ["handle"],
28+
"properties": {
29+
"handle": {
30+
"type": "string",
31+
"format": "handle",
32+
"description": "The handle to resolve."
33+
}
34+
}
35+
},
36+
"description": "Resolves an atproto handle (hostname) to a DID. Does not necessarily bi-directionally verify against the the DID document."
37+
}
38+
},
39+
"$type": "com.atproto.lexicon.schema",
40+
"lexicon": 1
41+
}

server/api/atproto/bluesky-oembed.get.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
BLUESKY_URL_EXTRACT_REGEX,
99
} from '#shared/utils/constants'
1010
import { type BlueskyOEmbedResponse, BlueskyOEmbedRequestSchema } from '#shared/schemas/atproto'
11+
import { Client } from '@atproto/lex'
12+
import * as com from '#shared/types/lexicons/com'
1113

1214
export 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

Comments
 (0)