From 174b2b2d83ea4831f4afc3c7162eb64a0c8bd4d1 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Mon, 12 Dec 2022 21:59:35 +0100 Subject: [PATCH] throw 404 --- components/status/StatusPreviewCard.vue | 5 +++-- server/api/og-image/[url].ts | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/components/status/StatusPreviewCard.vue b/components/status/StatusPreviewCard.vue index bcc88a43..fe865a4e 100644 --- a/components/status/StatusPreviewCard.vue +++ b/components/status/StatusPreviewCard.vue @@ -13,8 +13,9 @@ const alt = $computed(() => `${props.card.title} - ${props.card.title}`) const isSquare = $computed(() => props.smallPictureOnly || props.card.width === props.card.height) const providerName = $computed(() => props.card.providerName ? props.card.providerName : new URL(props.card.url).hostname) const imageSrcset = $computed(() => props.card.image - ? `${props.card.image}, /api/og-image/${encodeURIComponent(props.card.url)}?fallbackUrl=${encodeURIComponent(props.card.image)} 2x` - : '') + ? `${props.card.image}, /api/og-image/${encodeURIComponent(props.card.url)} 2x` + : '', +) // TODO: handle card.type: 'photo' | 'video' | 'rich'; diff --git a/server/api/og-image/[url].ts b/server/api/og-image/[url].ts index 126abda2..b67e69a2 100644 --- a/server/api/og-image/[url].ts +++ b/server/api/og-image/[url].ts @@ -38,7 +38,6 @@ async function resolveOgImageUrlManually(cardUrl: string): Promise { export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const { url } = getRouterParams(event) - const { fallbackUrl } = getQuery(event) const cardUrl = decodeURIComponent(url) @@ -78,8 +77,11 @@ export default defineEventHandler(async (event) => { } if (!ogImageUrl) { - // If nothing helped, set cardUrl as default - ogImageUrl = decodeURIComponent(fallbackUrl as string) + // If nothing helped, send 404 so the srcset can fallback to the default image + throw createError({ + statusCode: 404, + statusMessage: 'Could not find og:image.', + }) } await sendRedirect(event, ogImageUrl)