From 1abe9f3a94be74f3d632b2772d87324e67fd5954 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Sat, 3 Jan 2026 14:47:40 +0100 Subject: [PATCH] fix(server): use hash instead of file counting for the cache key --- server/api/gallery.get.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/api/gallery.get.ts b/server/api/gallery.get.ts index 0c41088..b8beb1c 100644 --- a/server/api/gallery.get.ts +++ b/server/api/gallery.get.ts @@ -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"; }