X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fconfig.ts;h=1aeadbe65f9da8ed945f14708ede957dc3653249;hb=45570e93974fd8902a724c24f5a10aea747350e0;hp=faabf17d7156c8684f9b895cc65b3fea578a688b;hpb=b7085c713220c9c5a96c9bb77330c2ba6ae9274e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index faabf17d7..1aeadbe65 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -2,21 +2,20 @@ 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'), body('instance.shortDescription').exists().withMessage('Should have a valid instance short description'), body('instance.description').exists().withMessage('Should have a valid instance description'), body('instance.terms').exists().withMessage('Should have a valid instance terms'), - body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'), + body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'), body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'), @@ -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'), @@ -39,6 +40,7 @@ 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.concurrency').isInt({ min: 1 }).withMessage('Should have a valid transcoding concurrency 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'), @@ -51,9 +53,13 @@ const customConfigUpdateValidator = [ 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.concurrency').isInt({ min: 0 }).withMessage('Should have a valid import concurrency number'), 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'), + body('trending.videos.algorithms.default').exists().withMessage('Should have a valid default trending algorithm'), + body('trending.videos.algorithms.enabled').exists().withMessage('Should have a valid array of enabled trending algorithms'), + body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), @@ -108,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 } @@ -121,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 } @@ -134,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 }