Files

35 lines
949 B
TypeScript
Raw Permalink Normal View History

import { readFile } from "node:fs/promises";
import path from "node:path";
import { configStore } from "@/lib/config/loader";
export const dynamic = "force-dynamic";
const CONFIG_DIR = path.join(process.cwd(), "config");
export async function GET(): Promise<Response> {
let customCssPath: string | undefined;
try {
customCssPath = configStore.get().theme.customCssPath;
} catch {
return new Response("", { status: 204 });
}
if (!customCssPath) {
return new Response("", { status: 204 });
}
const resolved = path.normalize(path.join(CONFIG_DIR, customCssPath));
if (!resolved.startsWith(CONFIG_DIR + path.sep)) {
return new Response("", { status: 204 });
}
try {
const css = await readFile(resolved, "utf-8");
return new Response(css, {
headers: { "Content-Type": "text/css; charset=utf-8", "Cache-Control": "no-cache" },
});
} catch {
return new Response("", { status: 204 });
}
}