From 7048db9d767471453e15c2e03bc21efca8703397 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 22 Oct 2025 14:30:49 +0200 Subject: [PATCH] fix: make image loading more robust --- src/components/Image.astro | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Image.astro b/src/components/Image.astro index 3ce039a..75386a4 100644 --- a/src/components/Image.astro +++ b/src/components/Image.astro @@ -2,6 +2,7 @@ import type { ImageMetadata } from "astro"; import { Picture as AstroImage } from "astro:assets"; import { generateThumbHash, getExifData } from "@helpers/image"; +import sharp from "sharp"; interface Props { src: ImageMetadata & { fsPath?: string }; alt: string; @@ -16,12 +17,12 @@ interface Props { async function checkImage(src: string) { try { if (src.startsWith("/@fs") || src.startsWith("/_astro")) return true; - const res = await fetch(src); - if (res.ok) { + const res = await sharp(src).metadata(); + if (res.format) { return true; - }else { + }else { console.log("Failed to fetch: ", src); - } + } return false; } catch (err) { console.log("Failed to fetch: ", src);