1 import type { Request, Response } from "express";
2 import { existsSync } from "fs";
3 import path from "path";
5 const extraThemesFolder =
6 process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes";
8 export default async (req: Request, res: Response) => {
9 res.contentType("text/css");
11 const theme = req.params.name;
13 if (!theme.endsWith(".css")) {
14 return res.status(400).send("Theme must be a css file");
17 const customTheme = path.resolve(extraThemesFolder, theme);
19 if (existsSync(customTheme)) {
20 return res.sendFile(customTheme);
22 const internalTheme = path.resolve(`./dist/assets/css/themes/${theme}`);
24 // If the theme doesn't exist, just send litely
25 if (existsSync(internalTheme)) {
26 return res.sendFile(internalTheme);
28 return res.sendFile(path.resolve("./dist/assets/css/themes/litely.css"));