From 6f433e08ceeb0e6f7402395b971d54185c3b68a2 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 21 Jun 2024 16:26:23 +0200 Subject: [PATCH] feat: add exif data to image tags --- src/helpers/image.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/helpers/image.ts b/src/helpers/image.ts index 4d4f0af..d4cd669 100644 --- a/src/helpers/image.ts +++ b/src/helpers/image.ts @@ -47,16 +47,23 @@ const allowedExif = [ export async function getExifData(image: ImageMetadata) { const sharp = await getSharp(); if (!sharp) return; - const tags = await ExifReader.load((image as ImageMetadata & { fsPath: string }).fsPath, { async: true }); + try { + const tags = await ExifReader.load((image as ImageMetadata & { fsPath: string }).fsPath, { async: true }); - const out: Record = {}; - let hasExif = false; + const out: Record = {}; + let hasExif = false; - for (const key of allowedExif) { - if (!tags[key]) continue; - hasExif = true; - out[key] = tags[key].description; + for (const key of allowedExif) { + if (!tags[key]) continue; + hasExif = true; + out[key] = tags[key].description; + } + + return hasExif ? out : undefined; + } catch (error) { + + console.log("Error reading EXIF data", error); + return undefined } - return hasExif ? out : undefined; }