fix(server): use hash instead of file counting for the cache key
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user