+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.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'No plugin found named ' + npmName
+ })
+ }
+ if (withVersion && plugin.version !== req.params.pluginVersion) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'No plugin found named ' + npmName + ' with version ' + req.params.pluginVersion
+ })
+ }
+
+ res.locals.registeredPlugin = plugin
+
+ return next()
+ }
+ ])
+}
+
+const getExternalAuthValidator = [
+ param('authName').custom(exists).withMessage('Should have a valid auth name'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking getExternalAuthValidator parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+
+ const plugin = res.locals.registeredPlugin
+ if (!plugin.registerHelpers) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'No registered helpers were found for this plugin'
+ })
+ }
+
+ const externalAuth = plugin.registerHelpers.getExternalAuths().find(a => a.authName === req.params.authName)
+ if (!externalAuth) {
+ return res.fail({
+ status: HttpStatusCode.NOT_FOUND_404,
+ message: 'No external auths were found for this plugin'
+ })
+ }
+
+ res.locals.externalAuth = externalAuth
+
+ return next()
+ }
+]
+
+const pluginStaticDirectoryValidator = [