]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { body } from 'express-validator' |
fb719404 | 3 | import { isIntOrNull } from '@server/helpers/custom-validators/misc' |
8d8a037e | 4 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' |
576ad67a | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
503c6f44 | 6 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
fb719404 C |
7 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' |
8 | import { logger } from '../../helpers/logger' | |
503c6f44 | 9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
10363c74 | 10 | import { areValidationErrors } from './shared' |
8d8a037e | 11 | import { HttpStatusCode } from '@shared/models/http/http-error-codes' |
fd206f0b C |
12 | |
13 | const customConfigUpdateValidator = [ | |
901637bb | 14 | body('instance.name').exists().withMessage('Should have a valid instance name'), |
a4101923 | 15 | body('instance.shortDescription').exists().withMessage('Should have a valid instance short description'), |
901637bb C |
16 | body('instance.description').exists().withMessage('Should have a valid instance description'), |
17 | body('instance.terms').exists().withMessage('Should have a valid instance terms'), | |
0883b324 | 18 | body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'), |
3da68f0a | 19 | body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), |
901637bb C |
20 | body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'), |
21 | body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'), | |
a4101923 C |
22 | |
23 | body('services.twitter.username').exists().withMessage('Should have a valid twitter username'), | |
24 | body('services.twitter.whitelisted').isBoolean().withMessage('Should have a valid twitter whitelisted boolean'), | |
25 | ||
26 | body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'), | |
27 | body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'), | |
b3d5cb92 | 28 | body('cache.torrents.size').isInt().withMessage('Should have a valid torrents cache size'), |
a4101923 | 29 | |
fd206f0b C |
30 | body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), |
31 | body('signup.limit').isInt().withMessage('Should have a valid signup limit'), | |
a4101923 | 32 | body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'), |
1f256e7d | 33 | body('signup.minimumAge').isInt().withMessage("Should have a valid minimum age required"), |
a4101923 | 34 | |
fd206f0b | 35 | body('admin.email').isEmail().withMessage('Should have a valid administrator email'), |
a4101923 C |
36 | body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'), |
37 | ||
fd206f0b | 38 | body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'), |
a4101923 C |
39 | body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'), |
40 | ||
fd206f0b | 41 | body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'), |
a4101923 | 42 | body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'), |
fd206f0b | 43 | body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'), |
9129b769 | 44 | body('transcoding.concurrency').isInt({ min: 1 }).withMessage('Should have a valid transcoding concurrency number'), |
5c7d6508 | 45 | body('transcoding.resolutions.0p').isBoolean().withMessage('Should have a valid transcoding 0p resolution enabled boolean'), |
fd206f0b C |
46 | body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), |
47 | body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), | |
48 | body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), | |
49 | body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), | |
50 | body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), | |
b7085c71 | 51 | body('transcoding.resolutions.1440p').isBoolean().withMessage('Should have a valid transcoding 1440p resolution enabled boolean'), |
fb719404 | 52 | body('transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'), |
a4101923 | 53 | |
d7a25329 | 54 | body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'), |
04cda1d7 | 55 | body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'), |
d7a25329 | 56 | |
9129b769 | 57 | body('import.videos.concurrency').isInt({ min: 0 }).withMessage('Should have a valid import concurrency number'), |
5d08a6a7 | 58 | body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), |
a84b8fa5 | 59 | body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'), |
fd206f0b | 60 | |
ba5d4a84 RK |
61 | body('trending.videos.algorithms.default').exists().withMessage('Should have a valid default trending algorithm'), |
62 | body('trending.videos.algorithms.enabled').exists().withMessage('Should have a valid array of enabled trending algorithms'), | |
63 | ||
14893eb7 C |
64 | body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), |
65 | body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), | |
66 | ||
503c6f44 | 67 | body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), |
7cd4d2ba | 68 | |
72c33e71 C |
69 | body('broadcastMessage.enabled').isBoolean().withMessage('Should have a valid broadcast message enabled boolean'), |
70 | body('broadcastMessage.message').exists().withMessage('Should have a valid broadcast message'), | |
71 | body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'), | |
5fb2e288 C |
72 | body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'), |
73 | ||
fb719404 C |
74 | body('live.enabled').isBoolean().withMessage('Should have a valid live enabled boolean'), |
75 | body('live.allowReplay').isBoolean().withMessage('Should have a valid live allow replay boolean'), | |
c9bc850e | 76 | body('live.maxDuration').isInt().withMessage('Should have a valid live max duration'), |
a056ca48 C |
77 | body('live.maxInstanceLives').custom(isIntOrNull).withMessage('Should have a valid max instance lives'), |
78 | body('live.maxUserLives').custom(isIntOrNull).withMessage('Should have a valid max user lives'), | |
fb719404 C |
79 | body('live.transcoding.enabled').isBoolean().withMessage('Should have a valid live transcoding enabled boolean'), |
80 | body('live.transcoding.threads').isInt().withMessage('Should have a valid live transcoding threads'), | |
81 | body('live.transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), | |
82 | body('live.transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), | |
83 | body('live.transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), | |
84 | body('live.transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), | |
85 | body('live.transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), | |
b7085c71 | 86 | body('live.transcoding.resolutions.1440p').isBoolean().withMessage('Should have a valid transcoding 1440p resolution enabled boolean'), |
fb719404 C |
87 | body('live.transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'), |
88 | ||
5fb2e288 C |
89 | body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'), |
90 | body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'), | |
91 | body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'), | |
92 | body('search.searchIndex.url').exists().withMessage('Should have a valid search index URL'), | |
93 | body('search.searchIndex.disableLocalSearch').isBoolean().withMessage('Should have a valid search index disable local search boolean'), | |
94 | body('search.searchIndex.isDefaultSearch').isBoolean().withMessage('Should have a valid search index default enabled boolean'), | |
72c33e71 | 95 | |
a1587156 | 96 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
fd206f0b C |
97 | logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) |
98 | ||
99 | if (areValidationErrors(req, res)) return | |
fb719404 C |
100 | if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return |
101 | if (!checkInvalidTranscodingConfig(req.body, res)) return | |
102 | if (!checkInvalidLiveConfig(req.body, res)) return | |
fd206f0b C |
103 | |
104 | return next() | |
105 | } | |
106 | ] | |
107 | ||
8d8a037e JB |
108 | function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { |
109 | if (!CONFIG.WEBADMIN.CONFIGURATION.EDITS.ALLOWED) { | |
110 | return res.fail({ | |
111 | status: HttpStatusCode.METHOD_NOT_ALLOWED_405, | |
112 | message: 'Server configuration is static and cannot be edited' | |
113 | }) | |
114 | } | |
115 | return next() | |
116 | } | |
117 | ||
576ad67a JM |
118 | // --------------------------------------------------------------------------- |
119 | ||
fd206f0b | 120 | export { |
8d8a037e JB |
121 | customConfigUpdateValidator, |
122 | ensureConfigIsEditable | |
fd206f0b | 123 | } |
576ad67a JM |
124 | |
125 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | |
4c1c1709 | 126 | if (isEmailEnabled()) return true |
576ad67a JM |
127 | |
128 | if (customConfig.signup.requiresEmailVerification === true) { | |
76148b27 | 129 | res.fail({ message: 'Emailer is disabled but you require signup email verification.' }) |
576ad67a JM |
130 | return false |
131 | } | |
132 | ||
133 | return true | |
134 | } | |
d7a25329 C |
135 | |
136 | function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express.Response) { | |
137 | if (customConfig.transcoding.enabled === false) return true | |
138 | ||
139 | if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) { | |
76148b27 | 140 | res.fail({ message: 'You need to enable at least webtorrent transcoding or hls transcoding' }) |
d7a25329 C |
141 | return false |
142 | } | |
143 | ||
144 | return true | |
145 | } | |
fb719404 C |
146 | |
147 | function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) { | |
148 | if (customConfig.live.enabled === false) return true | |
149 | ||
150 | if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) { | |
76148b27 | 151 | res.fail({ message: 'You cannot allow live replay if transcoding is not enabled' }) |
fb719404 C |
152 | return false |
153 | } | |
154 | ||
155 | return true | |
156 | } |