feat(api): normalize logo name

This commit is contained in:
2026-02-22 14:06:15 +01:00
parent 5733342619
commit 3d53660319
3 changed files with 59 additions and 21 deletions

View File

@@ -1,22 +1,9 @@
import { readdir } from "fs/promises";
import { join } from "path";
import { createHash } from "crypto";
import { getLogoNames } from "../utils/logos";
const logosDir = import.meta.dev
? join(process.cwd(), "public/logos")
: join(process.cwd(), ".output/public/logos");
export default defineEventHandler(async () => {
const names = await getLogoNames();
if (!names)
throw createError({ statusCode: 500, message: "Could not retrieve logos" });
export default defineCachedEventHandler(async () => {
const files = await readdir(logosDir);
return files
.filter((f) => f.endsWith(".png"))
.map((f) => f.replace(/\.png$/, ""))
.sort();
}, {
maxAge: 60 * 60 * 24,
getKey: async () => {
const files = await readdir(logosDir);
const key = files.filter((f) => f.endsWith(".png")).sort().join(",");
return createHash("sha256").update(key).digest("hex");
},
return names;
});