]>
Commit | Line | Data |
---|---|---|
1 | import * as express from 'express' | |
2 | import { body } from 'express-validator' | |
3 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' | |
4 | import { logger } from '../../helpers/logger' | |
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | |
6 | import { areValidationErrors } from './utils' | |
7 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | |
8 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | |
9 | import { isEmailEnabled } from '@server/initializers/config' | |
10 | ||
11 | const customConfigUpdateValidator = [ | |
12 | body('instance.name').exists().withMessage('Should have a valid instance name'), | |
13 | body('instance.shortDescription').exists().withMessage('Should have a valid instance short description'), | |
14 | body('instance.description').exists().withMessage('Should have a valid instance description'), | |
15 | body('instance.terms').exists().withMessage('Should have a valid instance terms'), | |
16 | body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), | |
17 | body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'), | |
18 | body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'), | |
19 | body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'), | |
20 | ||
21 | body('services.twitter.username').exists().withMessage('Should have a valid twitter username'), | |
22 | body('services.twitter.whitelisted').isBoolean().withMessage('Should have a valid twitter whitelisted boolean'), | |
23 | ||
24 | body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'), | |
25 | body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'), | |
26 | ||
27 | body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), | |
28 | body('signup.limit').isInt().withMessage('Should have a valid signup limit'), | |
29 | body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'), | |
30 | ||
31 | body('admin.email').isEmail().withMessage('Should have a valid administrator email'), | |
32 | body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'), | |
33 | ||
34 | body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'), | |
35 | body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'), | |
36 | ||
37 | body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'), | |
38 | body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'), | |
39 | body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'), | |
40 | body('transcoding.resolutions.0p').isBoolean().withMessage('Should have a valid transcoding 0p resolution enabled boolean'), | |
41 | body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), | |
42 | body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), | |
43 | body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), | |
44 | body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), | |
45 | body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), | |
46 | ||
47 | body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'), | |
48 | body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'), | |
49 | ||
50 | body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), | |
51 | body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'), | |
52 | ||
53 | body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), | |
54 | body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), | |
55 | ||
56 | body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), | |
57 | ||
58 | body('broadcastMessage.enabled').isBoolean().withMessage('Should have a valid broadcast message enabled boolean'), | |
59 | body('broadcastMessage.message').exists().withMessage('Should have a valid broadcast message'), | |
60 | body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'), | |
61 | body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'), | |
62 | ||
63 | body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'), | |
64 | body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'), | |
65 | body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'), | |
66 | body('search.searchIndex.url').exists().withMessage('Should have a valid search index URL'), | |
67 | body('search.searchIndex.disableLocalSearch').isBoolean().withMessage('Should have a valid search index disable local search boolean'), | |
68 | body('search.searchIndex.isDefaultSearch').isBoolean().withMessage('Should have a valid search index default enabled boolean'), | |
69 | ||
70 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
71 | logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) | |
72 | ||
73 | if (areValidationErrors(req, res)) return | |
74 | if (!checkInvalidConfigIfEmailDisabled(req.body as CustomConfig, res)) return | |
75 | if (!checkInvalidTranscodingConfig(req.body as CustomConfig, res)) return | |
76 | ||
77 | return next() | |
78 | } | |
79 | ] | |
80 | ||
81 | // --------------------------------------------------------------------------- | |
82 | ||
83 | export { | |
84 | customConfigUpdateValidator | |
85 | } | |
86 | ||
87 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | |
88 | if (isEmailEnabled()) return true | |
89 | ||
90 | if (customConfig.signup.requiresEmailVerification === true) { | |
91 | res.status(400) | |
92 | .send({ error: 'Emailer is disabled but you require signup email verification.' }) | |
93 | .end() | |
94 | return false | |
95 | } | |
96 | ||
97 | return true | |
98 | } | |
99 | ||
100 | function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express.Response) { | |
101 | if (customConfig.transcoding.enabled === false) return true | |
102 | ||
103 | if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) { | |
104 | res.status(400) | |
105 | .send({ error: 'You need to enable at least webtorrent transcoding or hls transcoding' }) | |
106 | .end() | |
107 | return false | |
108 | } | |
109 | ||
110 | return true | |
111 | } |