]>
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' |
a85d5303 | 5 | import { HttpStatusCode } from '@shared/models/http/http-error-codes' |
576ad67a | 6 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
503c6f44 | 7 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
fb719404 | 8 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' |
503c6f44 | 9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' |
10363c74 | 10 | import { areValidationErrors } from './shared' |
fd206f0b C |
11 | |
12 | const customConfigUpdateValidator = [ | |
396f6f01 C |
13 | body('instance.name').exists(), |
14 | body('instance.shortDescription').exists(), | |
15 | body('instance.description').exists(), | |
16 | body('instance.terms').exists(), | |
17 | body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid), | |
18 | body('instance.defaultClientRoute').exists(), | |
19 | body('instance.customizations.css').exists(), | |
20 | body('instance.customizations.javascript').exists(), | |
21 | ||
22 | body('services.twitter.username').exists(), | |
23 | body('services.twitter.whitelisted').isBoolean(), | |
24 | ||
25 | body('cache.previews.size').isInt(), | |
26 | body('cache.captions.size').isInt(), | |
27 | body('cache.torrents.size').isInt(), | |
28 | ||
29 | body('signup.enabled').isBoolean(), | |
30 | body('signup.limit').isInt(), | |
31 | body('signup.requiresEmailVerification').isBoolean(), | |
e364e31e | 32 | body('signup.requiresApproval').isBoolean(), |
396f6f01 C |
33 | body('signup.minimumAge').isInt(), |
34 | ||
35 | body('admin.email').isEmail(), | |
36 | body('contactForm.enabled').isBoolean(), | |
37 | ||
b302c80d | 38 | body('user.history.videos.enabled').isBoolean(), |
396f6f01 C |
39 | body('user.videoQuota').custom(isUserVideoQuotaValid), |
40 | body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid), | |
41 | ||
42 | body('videoChannels.maxPerUser').isInt(), | |
43 | ||
44 | body('transcoding.enabled').isBoolean(), | |
45 | body('transcoding.allowAdditionalExtensions').isBoolean(), | |
46 | body('transcoding.threads').isInt(), | |
47 | body('transcoding.concurrency').isInt({ min: 1 }), | |
48 | body('transcoding.resolutions.0p').isBoolean(), | |
49 | body('transcoding.resolutions.144p').isBoolean(), | |
50 | body('transcoding.resolutions.240p').isBoolean(), | |
51 | body('transcoding.resolutions.360p').isBoolean(), | |
52 | body('transcoding.resolutions.480p').isBoolean(), | |
53 | body('transcoding.resolutions.720p').isBoolean(), | |
54 | body('transcoding.resolutions.1080p').isBoolean(), | |
55 | body('transcoding.resolutions.1440p').isBoolean(), | |
56 | body('transcoding.resolutions.2160p').isBoolean(), | |
0c9668f7 | 57 | body('transcoding.remoteRunners.enabled').isBoolean(), |
396f6f01 C |
58 | |
59 | body('transcoding.alwaysTranscodeOriginalResolution').isBoolean(), | |
60 | ||
61 | body('transcoding.webtorrent.enabled').isBoolean(), | |
62 | body('transcoding.hls.enabled').isBoolean(), | |
63 | ||
64 | body('videoStudio.enabled').isBoolean(), | |
5e47f6ab | 65 | body('videoStudio.remoteRunners.enabled').isBoolean(), |
396f6f01 C |
66 | |
67 | body('import.videos.concurrency').isInt({ min: 0 }), | |
68 | body('import.videos.http.enabled').isBoolean(), | |
69 | body('import.videos.torrent.enabled').isBoolean(), | |
70 | ||
71 | body('import.videoChannelSynchronization.enabled').isBoolean(), | |
72 | ||
73 | body('trending.videos.algorithms.default').exists(), | |
74 | body('trending.videos.algorithms.enabled').exists(), | |
75 | ||
76 | body('followers.instance.enabled').isBoolean(), | |
77 | body('followers.instance.manualApproval').isBoolean(), | |
78 | ||
79 | body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)), | |
80 | ||
81 | body('broadcastMessage.enabled').isBoolean(), | |
82 | body('broadcastMessage.message').exists(), | |
83 | body('broadcastMessage.level').exists(), | |
84 | body('broadcastMessage.dismissable').isBoolean(), | |
85 | ||
86 | body('live.enabled').isBoolean(), | |
87 | body('live.allowReplay').isBoolean(), | |
88 | body('live.maxDuration').isInt(), | |
89 | body('live.maxInstanceLives').custom(isIntOrNull), | |
90 | body('live.maxUserLives').custom(isIntOrNull), | |
91 | body('live.transcoding.enabled').isBoolean(), | |
92 | body('live.transcoding.threads').isInt(), | |
93 | body('live.transcoding.resolutions.144p').isBoolean(), | |
94 | body('live.transcoding.resolutions.240p').isBoolean(), | |
95 | body('live.transcoding.resolutions.360p').isBoolean(), | |
96 | body('live.transcoding.resolutions.480p').isBoolean(), | |
97 | body('live.transcoding.resolutions.720p').isBoolean(), | |
98 | body('live.transcoding.resolutions.1080p').isBoolean(), | |
99 | body('live.transcoding.resolutions.1440p').isBoolean(), | |
100 | body('live.transcoding.resolutions.2160p').isBoolean(), | |
101 | body('live.transcoding.alwaysTranscodeOriginalResolution').isBoolean(), | |
0c9668f7 | 102 | body('live.transcoding.remoteRunners.enabled').isBoolean(), |
396f6f01 C |
103 | |
104 | body('search.remoteUri.users').isBoolean(), | |
105 | body('search.remoteUri.anonymous').isBoolean(), | |
106 | body('search.searchIndex.enabled').isBoolean(), | |
107 | body('search.searchIndex.url').exists(), | |
108 | body('search.searchIndex.disableLocalSearch').isBoolean(), | |
109 | body('search.searchIndex.isDefaultSearch').isBoolean(), | |
72c33e71 | 110 | |
a1587156 | 111 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
fd206f0b | 112 | if (areValidationErrors(req, res)) return |
fb719404 C |
113 | if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return |
114 | if (!checkInvalidTranscodingConfig(req.body, res)) return | |
2a491182 | 115 | if (!checkInvalidSynchronizationConfig(req.body, res)) return |
fb719404 | 116 | if (!checkInvalidLiveConfig(req.body, res)) return |
92e66e04 | 117 | if (!checkInvalidVideoStudioConfig(req.body, res)) return |
fd206f0b C |
118 | |
119 | return next() | |
120 | } | |
121 | ] | |
122 | ||
8d8a037e | 123 | function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { |
cf0c8ee5 | 124 | if (!CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED) { |
8d8a037e JB |
125 | return res.fail({ |
126 | status: HttpStatusCode.METHOD_NOT_ALLOWED_405, | |
127 | message: 'Server configuration is static and cannot be edited' | |
128 | }) | |
129 | } | |
cf0c8ee5 | 130 | |
8d8a037e JB |
131 | return next() |
132 | } | |
133 | ||
576ad67a JM |
134 | // --------------------------------------------------------------------------- |
135 | ||
fd206f0b | 136 | export { |
8d8a037e JB |
137 | customConfigUpdateValidator, |
138 | ensureConfigIsEditable | |
fd206f0b | 139 | } |
576ad67a JM |
140 | |
141 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | |
4c1c1709 | 142 | if (isEmailEnabled()) return true |
576ad67a JM |
143 | |
144 | if (customConfig.signup.requiresEmailVerification === true) { | |
76148b27 | 145 | res.fail({ message: 'Emailer is disabled but you require signup email verification.' }) |
576ad67a JM |
146 | return false |
147 | } | |
148 | ||
149 | return true | |
150 | } | |
d7a25329 C |
151 | |
152 | function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express.Response) { | |
153 | if (customConfig.transcoding.enabled === false) return true | |
154 | ||
155 | if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) { | |
76148b27 | 156 | res.fail({ message: 'You need to enable at least webtorrent transcoding or hls transcoding' }) |
d7a25329 C |
157 | return false |
158 | } | |
159 | ||
160 | return true | |
161 | } | |
fb719404 | 162 | |
2a491182 F |
163 | function checkInvalidSynchronizationConfig (customConfig: CustomConfig, res: express.Response) { |
164 | if (customConfig.import.videoChannelSynchronization.enabled && !customConfig.import.videos.http.enabled) { | |
165 | res.fail({ message: 'You need to enable HTTP video import in order to enable channel synchronization' }) | |
166 | return false | |
167 | } | |
168 | return true | |
169 | } | |
170 | ||
fb719404 C |
171 | function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) { |
172 | if (customConfig.live.enabled === false) return true | |
173 | ||
174 | if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) { | |
76148b27 | 175 | res.fail({ message: 'You cannot allow live replay if transcoding is not enabled' }) |
fb719404 C |
176 | return false |
177 | } | |
178 | ||
179 | return true | |
180 | } | |
c729caf6 | 181 | |
92e66e04 C |
182 | function checkInvalidVideoStudioConfig (customConfig: CustomConfig, res: express.Response) { |
183 | if (customConfig.videoStudio.enabled === false) return true | |
c729caf6 | 184 | |
92e66e04 C |
185 | if (customConfig.videoStudio.enabled === true && customConfig.transcoding.enabled === false) { |
186 | res.fail({ message: 'You cannot enable video studio if transcoding is not enabled' }) | |
c729caf6 C |
187 | return false |
188 | } | |
189 | ||
190 | return true | |
191 | } |