X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fconfig.ts;h=41a6ae4f9aa856c1f60e1b8b899007d6b1ec2d56;hb=fb7194043d0486ce0a6a40b2ffbdf32878c33a6f;hp=5059ed0f2994a10ec328b28b77127695f74f9cfc;hpb=c8861d5dc0436ef4342ce517241e3591fa256a13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 5059ed0f2..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 { Emailer } from '../../lib/emailer' -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 { areValidationErrors } from './utils' const customConfigUpdateValidator = [ body('instance.name').exists().withMessage('Should have a valid instance name'), @@ -37,11 +38,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.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'), 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'), @@ -51,11 +57,37 @@ const customConfigUpdateValidator = [ body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), - async (req: express.Request, res: express.Response, next: express.NextFunction) => { + body('broadcastMessage.enabled').isBoolean().withMessage('Should have a valid broadcast message enabled boolean'), + body('broadcastMessage.message').exists().withMessage('Should have a valid broadcast message'), + 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'), + body('search.searchIndex.url').exists().withMessage('Should have a valid search index URL'), + body('search.searchIndex.disableLocalSearch').isBoolean().withMessage('Should have a valid search index disable local search boolean'), + body('search.searchIndex.isDefaultSearch').isBoolean().withMessage('Should have a valid search index default enabled boolean'), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) if (areValidationErrors(req, res)) return - if (!checkInvalidConfigIfEmailDisabled(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() } @@ -68,7 +100,7 @@ export { } function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { - if (Emailer.isEnabled()) return true + if (isEmailEnabled()) return true if (customConfig.signup.requiresEmailVerification === true) { res.status(400) @@ -79,3 +111,29 @@ 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 +} + +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 +}