]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/config.ts
Add video caption upload documentation and improve error message
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / config.ts
index 5059ed0f2994a10ec328b28b77127695f74f9cfc..2d1f61947036a7b095b24b11e2e4ce13b27beedc 100644 (file)
@@ -37,12 +37,16 @@ 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.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'),
   body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
   body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
   body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
 
+  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.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'),
 
@@ -56,6 +60,7 @@ const customConfigUpdateValidator = [
 
     if (areValidationErrors(req, res)) return
     if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return
+    if (!checkInvalidTranscodingConfig(req.body as CustomConfig, res)) return
 
     return next()
   }
@@ -79,3 +84,16 @@ function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: exp
 
   return true
 }
+
+function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express.Response) {
+  if (customConfig.transcoding.enabled === false) return true
+
+  if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) {
+    res.status(400)
+       .send({ error: 'You need to enable at least webtorrent transcoding or hls transcoding' })
+       .end()
+    return false
+  }
+
+  return true
+}