MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / getOpenGraphNinja

Function getOpenGraphNinja

app/services/uriPreview.server.ts:19–44  ·  view source on GitHub ↗
(link: string)

Source from the content-addressed store, hash-verified

17];
18
19async function getOpenGraphNinja(link: string): Promise<PreviewResult> {
20 const response = await fetchProxy(`https://opengraph.ninja/api/v1?url=${link}`);
21
22 if (response.ok) {
23 const body: OpenGraphPreviewData = await response.json();
24 return {
25 url: body.requestUrl,
26 contentType: 'html',
27 mimeType: 'text/html',
28 title: body.title,
29 description: body.description,
30 icon: { url: body.details.favicon ?? '' },
31 image: {
32 url: body.image?.url ?? '',
33 alt: body.image?.alt
34 }
35 };
36 } else {
37 const body: OpenGraphPreviewDataError = await response.json();
38
39 // Log the error instead of propagating the internal error to the UI
40 console.log(`OpenGraph Ninja failed to get preview data: ${body.error}`);
41
42 return { error: "No preview available for this URL" };
43 }
44}
45
46export async function getUriPreview(uri: string): Promise<PreviewResult> {
47 const url = rewriteUrl(uri);

Callers 1

getUriPreviewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected