"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serveThemeCSSValidator = void 0;
const express_validator_1 = require("express-validator");
const misc_1 = require("../../helpers/custom-validators/misc");
const plugins_1 = require("../../helpers/custom-validators/plugins");
const plugin_manager_1 = require("../../lib/plugins/plugin-manager");
const shared_1 = require("./shared");
const serveThemeCSSValidator = [
    (0, express_validator_1.param)('themeName')
        .custom(plugins_1.isPluginNameValid),
    (0, express_validator_1.param)('themeVersion')
        .custom(plugins_1.isPluginStableOrUnstableVersionValid),
    (0, express_validator_1.param)('staticEndpoint')
        .custom(misc_1.isSafePath),
    (req, res, next) => {
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        const theme = plugin_manager_1.PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName);
        if (!theme || theme.version !== req.params.themeVersion) {
            return res.fail({
                status: 404,
                message: 'No theme named ' + req.params.themeName + ' was found with version ' + req.params.themeVersion
            });
        }
        if (theme.css.includes(req.params.staticEndpoint) === false) {
            return res.fail({
                status: 404,
                message: 'No static endpoint was found for this theme'
            });
        }
        res.locals.registeredPlugin = theme;
        return next();
    }
];
exports.serveThemeCSSValidator = serveThemeCSSValidator;
//# sourceMappingURL=themes.js.map