From b32ca7d65eb4dd9658113f8d83ced13685d8b542 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 14 May 2025 19:48:55 +0200 Subject: [PATCH] feat: improve some error messages --- src/components/Image.astro | 4 ++-- src/helpers/image.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/Image.astro b/src/components/Image.astro index a29de48..634b62d 100644 --- a/src/components/Image.astro +++ b/src/components/Image.astro @@ -3,7 +3,7 @@ import type { ImageMetadata } from "astro"; import { Picture as AstroImage } from "astro:assets"; import { generateThumbHash, getExifData } from "@helpers/image"; interface Props { - src: ImageMetadata; + src: ImageMetadata & { fsPath?: string }; alt: string; pictureClass?: string; class?: string; @@ -22,7 +22,7 @@ const { maxWidth, } = Astro.props; -let thumbhash = hash ? await generateThumbHash(image) : ""; +let thumbhash = hash && image.fsPath ? await generateThumbHash(image) : ""; let exif = await getExifData(image); diff --git a/src/helpers/image.ts b/src/helpers/image.ts index abd7241..3b95a8c 100644 --- a/src/helpers/image.ts +++ b/src/helpers/image.ts @@ -9,7 +9,7 @@ async function getSharp(): Promise { return s; } -export async function generateThumbHash(image: ImageMetadata) { +export async function generateThumbHash(image: ImageMetadata & { fsPath?: string }) { const sharp = await getSharp(); if (!sharp) return; @@ -20,7 +20,6 @@ export async function generateThumbHash(image: ImageMetadata) { const smallHeight = Math.floor(image.height * scaleFactor); try { - //@ts-ignore const smallImg = await sharp(image.fsPath) .resize(smallWidth, smallHeight) .withMetadata() @@ -31,9 +30,8 @@ export async function generateThumbHash(image: ImageMetadata) { const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg); return Buffer.from(buffer).toString("base64"); } catch (error) { - //@ts-ignore console.log(`Could not generate thumbhash for ${image.fsPath}`, error) - return undefined + return "" } }