tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
catch constellation errors
awarm.space
4 months ago
0f29e2f2
9a3d8d68
+23
-19
1 changed file
expand all
collapse all
unified
split
app
lish
[did]
[publication]
[rkey]
getPostPageData.ts
+23
-19
app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
···
60
60
export async function getConstellationBacklinks(
61
61
url: string,
62
62
): Promise<{ uri: string }[]> {
63
63
-
let baseURL = `https://constellation.microcosm.blue/xrpc/blue.microcosm.links.getBacklinks?subject=${encodeURIComponent(url)}`;
64
64
-
let externalEmbeds = new URL(
65
65
-
`${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:embed.external.uri")}`,
66
66
-
);
67
67
-
let linkFacets = new URL(
68
68
-
`${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:facets[].features[app.bsky.richtext.facet#link].uri")}`,
69
69
-
);
63
63
+
try {
64
64
+
let baseURL = `https://constellation.microcosm.blue/xrpc/blue.microcosm.links.getBacklinks?subject=${encodeURIComponent(url)}`;
65
65
+
let externalEmbeds = new URL(
66
66
+
`${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:embed.external.uri")}`,
67
67
+
);
68
68
+
let linkFacets = new URL(
69
69
+
`${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:facets[].features[app.bsky.richtext.facet#link].uri")}`,
70
70
+
);
70
71
71
71
-
let [links, embeds] = (await Promise.all([
72
72
-
fetch(linkFacets, { headers, next: { revalidate: 3600 } }).then((req) =>
73
73
-
req.json(),
74
74
-
),
75
75
-
fetch(externalEmbeds, { headers, next: { revalidate: 3600 } }).then((req) =>
76
76
-
req.json(),
77
77
-
),
78
78
-
])) as ConstellationResponse[];
72
72
+
let [links, embeds] = (await Promise.all([
73
73
+
fetch(linkFacets, { headers, next: { revalidate: 3600 } }).then((req) =>
74
74
+
req.json(),
75
75
+
),
76
76
+
fetch(externalEmbeds, { headers, next: { revalidate: 3600 } }).then(
77
77
+
(req) => req.json(),
78
78
+
),
79
79
+
])) as ConstellationResponse[];
79
80
80
80
-
let uris = [...links.records, ...embeds.records].map((i) =>
81
81
-
AtUri.make(i.did, i.collection, i.rkey).toString(),
82
82
-
);
81
81
+
let uris = [...links.records, ...embeds.records].map((i) =>
82
82
+
AtUri.make(i.did, i.collection, i.rkey).toString(),
83
83
+
);
83
84
84
84
-
return uris.map((uri) => ({ uri }));
85
85
+
return uris.map((uri) => ({ uri }));
86
86
+
} catch (e) {
87
87
+
return [];
88
88
+
}
85
89
}
86
90
87
91
type ConstellationResponse = {