]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/config.ts
Fix search with bad webfinger handles
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / config.ts
1 import * as express from 'express'
2 import { body } from 'express-validator/check'
3 import { isUserNSFWPolicyValid, isUserVideoQuotaValid, isUserVideoQuotaDailyValid } from '../../helpers/custom-validators/users'
4 import { logger } from '../../helpers/logger'
5 import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6 import { Emailer } from '../../lib/emailer'
7 import { areValidationErrors } from './utils'
8
9 const customConfigUpdateValidator = [
10 body('instance.name').exists().withMessage('Should have a valid instance name'),
11 body('instance.shortDescription').exists().withMessage('Should have a valid instance short description'),
12 body('instance.description').exists().withMessage('Should have a valid instance description'),
13 body('instance.terms').exists().withMessage('Should have a valid instance terms'),
14 body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'),
15 body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'),
16 body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'),
17 body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'),
18
19 body('services.twitter.username').exists().withMessage('Should have a valid twitter username'),
20 body('services.twitter.whitelisted').isBoolean().withMessage('Should have a valid twitter whitelisted boolean'),
21
22 body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'),
23 body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'),
24
25 body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'),
26 body('signup.limit').isInt().withMessage('Should have a valid signup limit'),
27 body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'),
28
29 body('admin.email').isEmail().withMessage('Should have a valid administrator email'),
30 body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'),
31
32 body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'),
33 body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'),
34
35 body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'),
36 body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'),
37 body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'),
38 body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'),
39 body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'),
40 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
41 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
42 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
43
44 body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'),
45 body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'),
46
47 body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'),
48 body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'),
49
50 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
51 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
52
53 if (areValidationErrors(req, res)) return
54 if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return
55
56 return next()
57 }
58 ]
59
60 // ---------------------------------------------------------------------------
61
62 export {
63 customConfigUpdateValidator
64 }
65
66 function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {
67 if (Emailer.isEnabled()) return true
68
69 if (customConfig.signup.requiresEmailVerification === true) {
70 res.status(400)
71 .send({ error: 'Emailer is disabled but you require signup email verification.' })
72 .end()
73 return false
74 }
75
76 return true
77 }