fix: some stuff

This commit is contained in:
Max Richter
2025-10-24 15:53:52 +02:00
parent bfe968c78f
commit 84d1c5b6fd
3 changed files with 10 additions and 5 deletions

View File

@@ -9,6 +9,7 @@
const iso = (d: string | Date) => {
if(!d) return ""
const v = toDate(d);
if(!v) return ""
return isNaN(v.getTime()) ? "" : v.toISOString();
};

Binary file not shown.

View File

@@ -1,6 +1,7 @@
import { rgbaToThumbHash } from "thumbhash";
import ExifReader from "exifreader";
import type { ImageMetadata } from "astro";
import { readFile } from "node:fs/promises";
import sharp from "sharp";
export async function generateThumbHash(
@@ -72,23 +73,26 @@ const allowedExif = [
];
export async function getExifData(image: ImageMetadata) {
if (image.format === "svg") return undefined; // SVGs don't have EXIF data")
if (image.format === "svg") return undefined; // SVGs don't have EXIF data
const imagePath = (image as ImageMetadata & { fsPath: string }).fsPath ??
image.src;
if (!imagePath) return undefined;
try {
let buffer: ArrayBuffer;
let buffer: ArrayBufferLike;
if (imagePath.startsWith("https://") || imagePath.startsWith("http://")) {
const res = await fetch(imagePath);
buffer = await res.arrayBuffer();
} else {
buffer = await sharp(imagePath).toBuffer() as unknown as ArrayBuffer;
const b = await readFile(imagePath);
buffer = b.buffer;
}
const tags = await ExifReader.load(buffer, { async: true });
if (!buffer) return undefined;
const out: Record<string, any> = {};
let hasExif = false;