WIP plugins: add ability to register plugins
This commit is contained in:
parent
297067399d
commit
345da516fa
23 changed files with 553 additions and 3 deletions
35
server/middlewares/validators/plugins.ts
Normal file
35
server/middlewares/validators/plugins.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import * as express from 'express'
|
||||
import { param } from 'express-validator/check'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { areValidationErrors } from './utils'
|
||||
import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
|
||||
import { PluginManager } from '../../lib/plugins/plugin-manager'
|
||||
import { isSafePath } from '../../helpers/custom-validators/misc'
|
||||
|
||||
const servePluginStaticDirectoryValidator = [
|
||||
param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'),
|
||||
param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin version'),
|
||||
param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking servePluginStaticDirectory parameters', { parameters: req.params })
|
||||
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
||||
const plugin = PluginManager.Instance.getRegisteredPlugin(req.params.pluginName)
|
||||
|
||||
if (!plugin || plugin.version !== req.params.pluginVersion) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
res.locals.registeredPlugin = plugin
|
||||
|
||||
return next()
|
||||
}
|
||||
]
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
servePluginStaticDirectoryValidator
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue