X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fconfig.ts;h=1aeadbe65f9da8ed945f14708ede957dc3653249;hb=45570e93974fd8902a724c24f5a10aea747350e0;hp=71098ff9941e8ab24668d9689853bffc2251dac7;hpb=9129b7694d577322327ee79e9b9aa64deee92765;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 71098ff99..1aeadbe65 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -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'), @@ -25,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'), @@ -113,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 } @@ -126,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 } @@ -139,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 }