aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/config.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/config.ts')
-rw-r--r--server/middlewares/validators/config.ts40
1 files changed, 34 insertions, 6 deletions
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index d3669f6be..41a6ae4f9 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator' 2import { body } from 'express-validator'
3import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' 3import { isIntOrNull } from '@server/helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger' 4import { isEmailEnabled } from '@server/initializers/config'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { areValidationErrors } from './utils'
7import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 6import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
7import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
8import { logger } from '../../helpers/logger'
8import { isThemeRegistered } from '../../lib/plugins/theme-utils' 9import { isThemeRegistered } from '../../lib/plugins/theme-utils'
9import { isEmailEnabled } from '@server/initializers/config' 10import { areValidationErrors } from './utils'
10 11
11const customConfigUpdateValidator = [ 12const customConfigUpdateValidator = [
12 body('instance.name').exists().withMessage('Should have a valid instance name'), 13 body('instance.name').exists().withMessage('Should have a valid instance name'),
@@ -43,6 +44,7 @@ const customConfigUpdateValidator = [
43 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), 44 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
44 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), 45 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
45 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), 46 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
47 body('transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'),
46 48
47 body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'), 49 body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'),
48 body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'), 50 body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'),
@@ -60,6 +62,18 @@ const customConfigUpdateValidator = [
60 body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'), 62 body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'),
61 body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'), 63 body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'),
62 64
65 body('live.enabled').isBoolean().withMessage('Should have a valid live enabled boolean'),
66 body('live.allowReplay').isBoolean().withMessage('Should have a valid live allow replay boolean'),
67 body('live.maxDuration').custom(isIntOrNull).withMessage('Should have a valid live max duration'),
68 body('live.transcoding.enabled').isBoolean().withMessage('Should have a valid live transcoding enabled boolean'),
69 body('live.transcoding.threads').isInt().withMessage('Should have a valid live transcoding threads'),
70 body('live.transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
71 body('live.transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
72 body('live.transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
73 body('live.transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
74 body('live.transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
75 body('live.transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'),
76
63 body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'), 77 body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'),
64 body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'), 78 body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'),
65 body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'), 79 body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'),
@@ -71,8 +85,9 @@ const customConfigUpdateValidator = [
71 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) 85 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
72 86
73 if (areValidationErrors(req, res)) return 87 if (areValidationErrors(req, res)) return
74 if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return 88 if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return
75 if (!checkInvalidTranscodingConfig(req.body as CustomConfig, res)) return 89 if (!checkInvalidTranscodingConfig(req.body, res)) return
90 if (!checkInvalidLiveConfig(req.body, res)) return
76 91
77 return next() 92 return next()
78 } 93 }
@@ -109,3 +124,16 @@ function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express
109 124
110 return true 125 return true
111} 126}
127
128function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) {
129 if (customConfig.live.enabled === false) return true
130
131 if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) {
132 res.status(400)
133 .send({ error: 'You cannot allow live replay if transcoding is not enabled' })
134 .end()
135 return false
136 }
137
138 return true
139}