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