]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/config.ts
Fix upload without files
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / config.ts
index 0efe1157ff9457a142f0a8ccf805716df08fe182..1aeadbe65f9da8ed945f14708ede957dc3653249 100644 (file)
@@ -2,13 +2,12 @@ import * as express from 'express'
 import { body } from 'express-validator'
 import { isIntOrNull } from '@server/helpers/custom-validators/misc'
 import { isEmailEnabled } from '@server/initializers/config'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 import { CustomConfig } from '../../../shared/models/server/custom-config.model'
 import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
 import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
 import { logger } from '../../helpers/logger'
 import { isThemeRegistered } from '../../lib/plugins/theme-utils'
-import { areValidationErrors } from './utils'
+import { areValidationErrors } from './shared'
 
 const customConfigUpdateValidator = [
   body('instance.name').exists().withMessage('Should have a valid instance name'),
@@ -17,7 +16,6 @@ const customConfigUpdateValidator = [
   body('instance.terms').exists().withMessage('Should have a valid instance terms'),
   body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'),
   body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'),
-  body('instance.defaultTrendingRoute').exists().withMessage('Should have a valid instance default trending route'),
   body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'),
   body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'),
 
@@ -26,10 +24,12 @@ const customConfigUpdateValidator = [
 
   body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'),
   body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'),
+  body('cache.torrents.size').isInt().withMessage('Should have a valid torrents cache size'),
 
   body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'),
   body('signup.limit').isInt().withMessage('Should have a valid signup limit'),
   body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'),
+  body('signup.minimumAge').isInt().withMessage("Should have a valid minimum age required"),
 
   body('admin.email').isEmail().withMessage('Should have a valid administrator email'),
   body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'),
@@ -40,6 +40,7 @@ const customConfigUpdateValidator = [
   body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'),
   body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'),
   body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'),
+  body('transcoding.concurrency').isInt({ min: 1 }).withMessage('Should have a valid transcoding concurrency number'),
   body('transcoding.resolutions.0p').isBoolean().withMessage('Should have a valid transcoding 0p resolution enabled boolean'),
   body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
   body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
@@ -52,9 +53,13 @@ const customConfigUpdateValidator = [
   body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'),
   body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'),
 
+  body('import.videos.concurrency').isInt({ min: 0 }).withMessage('Should have a valid import concurrency number'),
   body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'),
   body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'),
 
+  body('trending.videos.algorithms.default').exists().withMessage('Should have a valid default trending algorithm'),
+  body('trending.videos.algorithms.enabled').exists().withMessage('Should have a valid array of enabled trending algorithms'),
+
   body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'),
   body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'),
 
@@ -109,9 +114,7 @@ function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: exp
   if (isEmailEnabled()) return true
 
   if (customConfig.signup.requiresEmailVerification === true) {
-    res.status(HttpStatusCode.BAD_REQUEST_400)
-       .send({ error: 'Emailer is disabled but you require signup email verification.' })
-       .end()
+    res.fail({ message: 'Emailer is disabled but you require signup email verification.' })
     return false
   }
 
@@ -122,9 +125,7 @@ function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express
   if (customConfig.transcoding.enabled === false) return true
 
   if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) {
-    res.status(HttpStatusCode.BAD_REQUEST_400)
-       .send({ error: 'You need to enable at least webtorrent transcoding or hls transcoding' })
-       .end()
+    res.fail({ message: 'You need to enable at least webtorrent transcoding or hls transcoding' })
     return false
   }
 
@@ -135,9 +136,7 @@ function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Respon
   if (customConfig.live.enabled === false) return true
 
   if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) {
-    res.status(HttpStatusCode.BAD_REQUEST_400)
-       .send({ error: 'You cannot allow live replay if transcoding is not enabled' })
-       .end()
+    res.fail({ message: 'You cannot allow live replay if transcoding is not enabled' })
     return false
   }