From fb7194043d0486ce0a6a40b2ffbdf32878c33a6f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 25 Sep 2020 16:19:35 +0200 Subject: Check live duration and size --- server/middlewares/validators/config.ts | 40 ++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'server/middlewares/validators/config.ts') 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 @@ import * as express from 'express' import { body } from 'express-validator' -import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' -import { logger } from '../../helpers/logger' +import { isIntOrNull } from '@server/helpers/custom-validators/misc' +import { isEmailEnabled } from '@server/initializers/config' import { CustomConfig } from '../../../shared/models/server/custom-config.model' -import { areValidationErrors } from './utils' 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 { isEmailEnabled } from '@server/initializers/config' +import { areValidationErrors } from './utils' const customConfigUpdateValidator = [ body('instance.name').exists().withMessage('Should have a valid instance name'), @@ -43,6 +44,7 @@ const customConfigUpdateValidator = [ 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.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p 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'), @@ -60,6 +62,18 @@ const customConfigUpdateValidator = [ body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'), body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'), + body('live.enabled').isBoolean().withMessage('Should have a valid live enabled boolean'), + body('live.allowReplay').isBoolean().withMessage('Should have a valid live allow replay boolean'), + body('live.maxDuration').custom(isIntOrNull).withMessage('Should have a valid live max duration'), + body('live.transcoding.enabled').isBoolean().withMessage('Should have a valid live transcoding enabled boolean'), + body('live.transcoding.threads').isInt().withMessage('Should have a valid live transcoding threads'), + body('live.transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), + body('live.transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), + body('live.transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), + body('live.transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), + body('live.transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), + body('live.transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'), + body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'), body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'), body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'), @@ -71,8 +85,9 @@ const customConfigUpdateValidator = [ logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return - if (!checkInvalidTranscodingConfig(req.body as CustomConfig, res)) return + if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return + if (!checkInvalidTranscodingConfig(req.body, res)) return + if (!checkInvalidLiveConfig(req.body, res)) return return next() } @@ -109,3 +124,16 @@ function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express return true } + +function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) { + if (customConfig.live.enabled === false) return true + + if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) { + res.status(400) + .send({ error: 'You cannot allow live replay if transcoding is not enabled' }) + .end() + return false + } + + return true +} -- cgit v1.2.3