2023-06-16 14:34:36 +00:00
|
|
|
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-16 14:34:36 +00:00
|
|
|
}
|
|
|
|
|
2023-06-20 22:37:48 +00:00
|
|
|
const customTheme = path.resolve(extraThemesFolder, theme);
|
2023-06-16 14:34:36 +00:00
|
|
|
|
|
|
|
if (existsSync(customTheme)) {
|
2023-06-25 14:47:21 +00:00
|
|
|
return res.sendFile(customTheme);
|
2023-06-16 14:34:36 +00:00
|
|
|
} 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);
|
2023-06-16 14:34:36 +00:00
|
|
|
} else {
|
2023-06-25 14:47:21 +00:00
|
|
|
return res.sendFile(path.resolve("./dist/assets/css/themes/litely.css"));
|
2023-06-16 14:34:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|