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

Function getUriPreview

app/services/uriPreview.server.ts:46–81  ·  view source on GitHub ↗
(uri: string)

Source from the content-addressed store, hash-verified

44}
45
46export async function getUriPreview(uri: string): Promise<PreviewResult> {
47 const url = rewriteUrl(uri);
48
49 const head = await headUri(url.href);
50
51 // If the url is an image content type, return a preview image
52 if (
53 head &&
54 imageContentTypes.some((contentType) =>
55 contentType.includes(head.contentType)
56 )
57 ) {
58 const previewImage = createPreviewImage(url.href, head);
59
60 return previewImage;
61 }
62
63 // If the url is a json content type, attempt to request the json and return a preview json
64 if (head?.contentType.includes("application/json")) {
65 const response = await safeFetch(url.href, {
66 headers: {
67 accept: "application/json",
68 },
69 });
70
71 if (!response.ok) {
72 return { error: "No preview available for this URL" };
73 }
74
75 const jsonBody = await response.json();
76
77 return createPreviewJson(url.href, jsonBody);
78 }
79
80 return await getOpenGraphNinja(url.href);
81}
82
83type HeadInfo = {
84 contentType: string;

Callers 1

loaderFunction · 0.90

Calls 6

rewriteUrlFunction · 0.85
headUriFunction · 0.85
createPreviewImageFunction · 0.85
safeFetchFunction · 0.85
createPreviewJsonFunction · 0.85
getOpenGraphNinjaFunction · 0.85

Tested by

no test coverage detected