mirror of
https://github.com/elk-zone/elk.git
synced 2024-12-05 03:59:59 +03:00
throw 404
This commit is contained in:
parent
bb013ddd18
commit
174b2b2d83
2 changed files with 8 additions and 5 deletions
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue