fix(server): use hash instead of file counting for the cache key

This commit is contained in:
2026-01-03 14:47:40 +01:00
parent fa915b3165
commit bfe531afa6

View File

@@ -1,5 +1,6 @@
import { readdir } from "fs/promises";
import { join } from "path";
import { createHash } from "crypto";
import exifr from "exifr";
import { z } from "zod";
@@ -77,7 +78,9 @@ export default defineCachedEventHandler(
const imageFiles = files.filter((file) =>
/\.(jpg|jpeg|png|webp)$/i.test(file),
);
return `gallery:${imageFiles.length}`;
const filesConcat = imageFiles.sort().join("");
const hash = createHash("sha256").update(filesConcat).digest("hex");
return `gallery:${hash}`;
} catch {
return "gallery:0";
}