fix(gallery): filter out files without exif data
Some checks failed
Build and Push Docker Image / build (push) Failing after 1m48s
Some checks failed
Build and Push Docker Image / build (push) Failing after 1m48s
This commit is contained in:
@@ -29,38 +29,43 @@ export default defineCachedEventHandler(
|
|||||||
/\.(jpg|jpeg|png|webp)$/i.test(file),
|
/\.(jpg|jpeg|png|webp)$/i.test(file),
|
||||||
);
|
);
|
||||||
|
|
||||||
const imagesWithExif = await Promise.all(
|
const imagesWithExif = (
|
||||||
imageFiles.map(async (filename) => {
|
await Promise.all(
|
||||||
const filePath = join(galleryDir, filename);
|
imageFiles.map(async (filename) => {
|
||||||
const rawExif = await exifr.parse(filePath, {
|
const filePath = join(galleryDir, filename);
|
||||||
tiff: true,
|
const rawExif = await exifr.parse(filePath, {
|
||||||
exif: true,
|
tiff: true,
|
||||||
gps: false,
|
exif: true,
|
||||||
interop: false,
|
gps: false,
|
||||||
ifd1: false,
|
interop: false,
|
||||||
});
|
ifd1: false,
|
||||||
|
});
|
||||||
|
|
||||||
const exif = exifSchema.parse(rawExif);
|
if (!rawExif) return null;
|
||||||
|
const parsed = exifSchema.safeParse(rawExif);
|
||||||
|
if (!parsed.success) return null;
|
||||||
|
const exif = parsed.data;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filename,
|
filename,
|
||||||
url: `/gallery/${filename}`,
|
url: `/gallery/${filename}`,
|
||||||
width: exif.ExifImageWidth,
|
width: exif.ExifImageWidth,
|
||||||
height: exif.ExifImageHeight,
|
height: exif.ExifImageHeight,
|
||||||
exif: {
|
exif: {
|
||||||
date: exif.DateTimeOriginal,
|
date: exif.DateTimeOriginal,
|
||||||
camera: `${exif.Make} ${exif.Model}`,
|
camera: `${exif.Make} ${exif.Model}`,
|
||||||
lens: exif.LensModel,
|
lens: exif.LensModel,
|
||||||
settings: {
|
settings: {
|
||||||
aperture: `f/${exif.FNumber}`,
|
aperture: `f/${exif.FNumber}`,
|
||||||
shutter: `1/${Math.round(1 / exif.ExposureTime)}s`,
|
shutter: `1/${Math.round(1 / exif.ExposureTime)}s`,
|
||||||
iso: String(exif.ISO),
|
iso: String(exif.ISO),
|
||||||
focalLength: `${exif.FocalLength}mm`,
|
focalLength: `${exif.FocalLength}mm`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
};
|
}),
|
||||||
}),
|
)
|
||||||
);
|
).filter((img) => img !== null);
|
||||||
|
|
||||||
return imagesWithExif;
|
return imagesWithExif;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user