lemmy-ui/src/server/handlers/theme-handler.ts

32 lines
884 B
TypeScript
Raw Normal View History

import type { Request, Response } from "express";
import { existsSync } from "fs";
import path from "path";
const extraThemesFolder =
process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes";
export default async (req: Request, res: Response) => {
res.contentType("text/css");
const theme = req.params.name;
if (!theme.endsWith(".css")) {
2023-06-25 14:43:58 +00:00
return res.status(400).send("Theme must be a css file");
}
2023-06-20 22:37:48 +00:00
const customTheme = path.resolve(extraThemesFolder, theme);
if (existsSync(customTheme)) {
2023-06-25 14:47:21 +00:00
return res.sendFile(customTheme);
} else {
const internalTheme = path.resolve(`./dist/assets/css/themes/${theme}`);
// If the theme doesn't exist, just send litely
if (existsSync(internalTheme)) {
2023-06-25 14:47:21 +00:00
return res.sendFile(internalTheme);
} else {
2023-06-25 14:47:21 +00:00
return res.sendFile(path.resolve("./dist/assets/css/themes/litely.css"));
}
}
};