throw 404

This commit is contained in:
Shinigami92 2022-12-12 21:59:35 +01:00
parent bb013ddd18
commit 174b2b2d83
2 changed files with 8 additions and 5 deletions

View file

@ -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';
</script>

View file

@ -38,7 +38,6 @@ async function resolveOgImageUrlManually(cardUrl: string): Promise<string> {
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)