-const servePluginStaticDirectoryValidator = (pluginType: PluginType) => [
- 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'),
+const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
+ const validators: (ValidationChain | express.Handler)[] = [
+ param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name')
+ ]
+
+ if (withVersion) {
+ validators.push(
+ param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin version')
+ )
+ }
+
+ return validators.concat([
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking getPluginValidator parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+
+ const npmName = PluginModel.buildNpmName(req.params.pluginName, pluginType)
+ const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(npmName)
+
+ if (!plugin) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
+ if (withVersion && plugin.version !== req.params.pluginVersion) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
+
+ res.locals.registeredPlugin = plugin
+
+ return next()
+ }
+ ])
+}
+
+const getExternalAuthValidator = [
+ param('authName').custom(exists).withMessage('Should have a valid auth name'),