| 17 | ]; |
| 18 | |
| 19 | async 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 | |
| 46 | export async function getUriPreview(uri: string): Promise<PreviewResult> { |
| 47 | const url = rewriteUrl(uri); |