fix: make image loading more robust
All checks were successful
Deploy to SFTP Server / build (push) Successful in 6m38s

This commit is contained in:
Max Richter
2025-10-22 14:30:49 +02:00
parent 0db489269b
commit 7048db9d76

View File

@@ -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,8 +17,8 @@ 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 {
console.log("Failed to fetch: ", src);