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 { readdir } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
import { createHash } from "crypto";
|
||||||
import exifr from "exifr";
|
import exifr from "exifr";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -77,7 +78,9 @@ export default defineCachedEventHandler(
|
|||||||
const imageFiles = files.filter((file) =>
|
const imageFiles = files.filter((file) =>
|
||||||
/\.(jpg|jpeg|png|webp)$/i.test(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 {
|
} catch {
|
||||||
return "gallery:0";
|
return "gallery:0";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user