2021-08-27 07:32:44 -05:00
|
|
|
import express from 'express'
|
2019-07-25 09:23:44 -05:00
|
|
|
import { param } from 'express-validator'
|
2021-07-16 03:42:24 -05:00
|
|
|
import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
|
2021-06-03 10:33:44 -05:00
|
|
|
import { isSafePath } from '../../helpers/custom-validators/misc'
|
2019-07-05 06:54:32 -05:00
|
|
|
import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
|
|
|
import { PluginManager } from '../../lib/plugins/plugin-manager'
|
2021-06-03 10:33:44 -05:00
|
|
|
import { areValidationErrors } from './shared'
|
2019-07-05 06:54:32 -05:00
|
|
|
|
|
|
|
const serveThemeCSSValidator = [
|
2022-08-17 07:27:04 -05:00
|
|
|
param('themeName')
|
|
|
|
.custom(isPluginNameValid),
|
|
|
|
param('themeVersion')
|
|
|
|
.custom(isPluginVersionValid),
|
|
|
|
param('staticEndpoint')
|
|
|
|
.custom(isSafePath),
|
2019-07-05 06:54:32 -05:00
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
2020-04-23 04:36:50 -05:00
|
|
|
const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName)
|
2019-07-05 06:54:32 -05:00
|
|
|
|
|
|
|
if (!theme || theme.version !== req.params.themeVersion) {
|
2021-05-31 18:36:53 -05:00
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.NOT_FOUND_404,
|
|
|
|
message: 'No theme named ' + req.params.themeName + ' was found with version ' + req.params.themeVersion
|
|
|
|
})
|
2019-07-05 06:54:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (theme.css.includes(req.params.staticEndpoint) === false) {
|
2021-05-31 18:36:53 -05:00
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.NOT_FOUND_404,
|
|
|
|
message: 'No static endpoint was found for this theme'
|
|
|
|
})
|
2019-07-05 06:54:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
res.locals.registeredPlugin = theme
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
serveThemeCSSValidator
|
|
|
|
}
|