+ return next()
+ }
+]
+
+const uninstallPluginValidator = [
+ body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking uninstallPluginValidator parameters', { parameters: req.body })
+
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
+
+const existingPluginValidator = [
+ param('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid plugin name'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking enabledPluginValidator parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+
+ const plugin = await PluginModel.loadByNpmName(req.params.npmName)
+ if (!plugin) {
+ return res.status(HttpStatusCode.NOT_FOUND_404)
+ .json({ error: 'Plugin not found' })
+ .end()
+ }
+
+ res.locals.plugin = plugin
+
+ return next()
+ }
+]
+
+const updatePluginSettingsValidator = [
+ body('settings').exists().withMessage('Should have settings'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body })
+
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
+
+const listAvailablePluginsValidator = [
+ query('search')
+ .optional()
+ .exists().withMessage('Should have a valid search'),
+ query('pluginType')
+ .optional()
+ .customSanitizer(toIntOrNull)
+ .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'),
+ query('currentPeerTubeEngine')
+ .optional()
+ .custom(isPluginVersionValid).withMessage('Should have a valid current peertube engine'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking enabledPluginValidator parameters', { parameters: req.query })
+
+ if (areValidationErrors(req, res)) return
+
+ if (CONFIG.PLUGINS.INDEX.ENABLED === false) {
+ return res.status(HttpStatusCode.BAD_REQUEST_400)
+ .json({ error: 'Plugin index is not enabled' })
+ .end()
+ }