From: n3oney Date: Tue, 20 Jun 2023 22:37:48 +0000 (+0200) Subject: Merge branch 'main' into patch-1 X-Git-Url: http://these/git/%22https:/image.com/%7B%7D/%7BpictshareAvatarThumbnail%28?a=commitdiff_plain;h=a7d91d3f2cd335ec0f805b6689439636ad27a39c;p=lemmy-ui.git Merge branch 'main' into patch-1 --- a7d91d3f2cd335ec0f805b6689439636ad27a39c diff --cc src/server/handlers/theme-handler.ts index 0000000,9f1046d..b107d85 mode 000000,100644..100644 --- a/src/server/handlers/theme-handler.ts +++ b/src/server/handlers/theme-handler.ts @@@ -1,0 -1,32 +1,32 @@@ + 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")) { + res.statusCode = 400; + res.send("Theme must be a css file"); + } + - const customTheme = path.resolve(`./${extraThemesFolder}/${theme}`); ++ const customTheme = path.resolve(extraThemesFolder, theme); + + if (existsSync(customTheme)) { + 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)) { + res.sendFile(internalTheme); + } else { + res.sendFile(path.resolve("./dist/assets/css/themes/litely.css")); + } + } + };