diff options
Diffstat (limited to 'server/middlewares/validators/config.ts')
-rw-r--r-- | server/middlewares/validators/config.ts | 194 |
1 files changed, 0 insertions, 194 deletions
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts deleted file mode 100644 index 7790025e4..000000000 --- a/server/middlewares/validators/config.ts +++ /dev/null | |||
@@ -1,194 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { body } from 'express-validator' | ||
3 | import { isIntOrNull } from '@server/helpers/custom-validators/misc' | ||
4 | import { CONFIG, isEmailEnabled } from '@server/initializers/config' | ||
5 | import { HttpStatusCode } from '@shared/models/http/http-error-codes' | ||
6 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | ||
7 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | ||
8 | import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' | ||
9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | ||
10 | import { areValidationErrors } from './shared' | ||
11 | |||
12 | const customConfigUpdateValidator = [ | ||
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 | body('cache.storyboards.size').isInt(), | ||
29 | |||
30 | body('signup.enabled').isBoolean(), | ||
31 | body('signup.limit').isInt(), | ||
32 | body('signup.requiresEmailVerification').isBoolean(), | ||
33 | body('signup.requiresApproval').isBoolean(), | ||
34 | body('signup.minimumAge').isInt(), | ||
35 | |||
36 | body('admin.email').isEmail(), | ||
37 | body('contactForm.enabled').isBoolean(), | ||
38 | |||
39 | body('user.history.videos.enabled').isBoolean(), | ||
40 | body('user.videoQuota').custom(isUserVideoQuotaValid), | ||
41 | body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid), | ||
42 | |||
43 | body('videoChannels.maxPerUser').isInt(), | ||
44 | |||
45 | body('transcoding.enabled').isBoolean(), | ||
46 | body('transcoding.allowAdditionalExtensions').isBoolean(), | ||
47 | body('transcoding.threads').isInt(), | ||
48 | body('transcoding.concurrency').isInt({ min: 1 }), | ||
49 | body('transcoding.resolutions.0p').isBoolean(), | ||
50 | body('transcoding.resolutions.144p').isBoolean(), | ||
51 | body('transcoding.resolutions.240p').isBoolean(), | ||
52 | body('transcoding.resolutions.360p').isBoolean(), | ||
53 | body('transcoding.resolutions.480p').isBoolean(), | ||
54 | body('transcoding.resolutions.720p').isBoolean(), | ||
55 | body('transcoding.resolutions.1080p').isBoolean(), | ||
56 | body('transcoding.resolutions.1440p').isBoolean(), | ||
57 | body('transcoding.resolutions.2160p').isBoolean(), | ||
58 | body('transcoding.remoteRunners.enabled').isBoolean(), | ||
59 | |||
60 | body('transcoding.alwaysTranscodeOriginalResolution').isBoolean(), | ||
61 | |||
62 | body('transcoding.webVideos.enabled').isBoolean(), | ||
63 | body('transcoding.hls.enabled').isBoolean(), | ||
64 | |||
65 | body('videoStudio.enabled').isBoolean(), | ||
66 | body('videoStudio.remoteRunners.enabled').isBoolean(), | ||
67 | |||
68 | body('videoFile.update.enabled').isBoolean(), | ||
69 | |||
70 | body('import.videos.concurrency').isInt({ min: 0 }), | ||
71 | body('import.videos.http.enabled').isBoolean(), | ||
72 | body('import.videos.torrent.enabled').isBoolean(), | ||
73 | |||
74 | body('import.videoChannelSynchronization.enabled').isBoolean(), | ||
75 | |||
76 | body('trending.videos.algorithms.default').exists(), | ||
77 | body('trending.videos.algorithms.enabled').exists(), | ||
78 | |||
79 | body('followers.instance.enabled').isBoolean(), | ||
80 | body('followers.instance.manualApproval').isBoolean(), | ||
81 | |||
82 | body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)), | ||
83 | |||
84 | body('broadcastMessage.enabled').isBoolean(), | ||
85 | body('broadcastMessage.message').exists(), | ||
86 | body('broadcastMessage.level').exists(), | ||
87 | body('broadcastMessage.dismissable').isBoolean(), | ||
88 | |||
89 | body('live.enabled').isBoolean(), | ||
90 | body('live.allowReplay').isBoolean(), | ||
91 | body('live.maxDuration').isInt(), | ||
92 | body('live.maxInstanceLives').custom(isIntOrNull), | ||
93 | body('live.maxUserLives').custom(isIntOrNull), | ||
94 | body('live.transcoding.enabled').isBoolean(), | ||
95 | body('live.transcoding.threads').isInt(), | ||
96 | body('live.transcoding.resolutions.144p').isBoolean(), | ||
97 | body('live.transcoding.resolutions.240p').isBoolean(), | ||
98 | body('live.transcoding.resolutions.360p').isBoolean(), | ||
99 | body('live.transcoding.resolutions.480p').isBoolean(), | ||
100 | body('live.transcoding.resolutions.720p').isBoolean(), | ||
101 | body('live.transcoding.resolutions.1080p').isBoolean(), | ||
102 | body('live.transcoding.resolutions.1440p').isBoolean(), | ||
103 | body('live.transcoding.resolutions.2160p').isBoolean(), | ||
104 | body('live.transcoding.alwaysTranscodeOriginalResolution').isBoolean(), | ||
105 | body('live.transcoding.remoteRunners.enabled').isBoolean(), | ||
106 | |||
107 | body('search.remoteUri.users').isBoolean(), | ||
108 | body('search.remoteUri.anonymous').isBoolean(), | ||
109 | body('search.searchIndex.enabled').isBoolean(), | ||
110 | body('search.searchIndex.url').exists(), | ||
111 | body('search.searchIndex.disableLocalSearch').isBoolean(), | ||
112 | body('search.searchIndex.isDefaultSearch').isBoolean(), | ||
113 | |||
114 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
115 | if (areValidationErrors(req, res)) return | ||
116 | if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return | ||
117 | if (!checkInvalidTranscodingConfig(req.body, res)) return | ||
118 | if (!checkInvalidSynchronizationConfig(req.body, res)) return | ||
119 | if (!checkInvalidLiveConfig(req.body, res)) return | ||
120 | if (!checkInvalidVideoStudioConfig(req.body, res)) return | ||
121 | |||
122 | return next() | ||
123 | } | ||
124 | ] | ||
125 | |||
126 | function ensureConfigIsEditable (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
127 | if (!CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED) { | ||
128 | return res.fail({ | ||
129 | status: HttpStatusCode.METHOD_NOT_ALLOWED_405, | ||
130 | message: 'Server configuration is static and cannot be edited' | ||
131 | }) | ||
132 | } | ||
133 | |||
134 | return next() | ||
135 | } | ||
136 | |||
137 | // --------------------------------------------------------------------------- | ||
138 | |||
139 | export { | ||
140 | customConfigUpdateValidator, | ||
141 | ensureConfigIsEditable | ||
142 | } | ||
143 | |||
144 | function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) { | ||
145 | if (isEmailEnabled()) return true | ||
146 | |||
147 | if (customConfig.signup.requiresEmailVerification === true) { | ||
148 | res.fail({ message: 'SMTP is not configured but you require signup email verification.' }) | ||
149 | return false | ||
150 | } | ||
151 | |||
152 | return true | ||
153 | } | ||
154 | |||
155 | function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express.Response) { | ||
156 | if (customConfig.transcoding.enabled === false) return true | ||
157 | |||
158 | if (customConfig.transcoding.webVideos.enabled === false && customConfig.transcoding.hls.enabled === false) { | ||
159 | res.fail({ message: 'You need to enable at least web_videos transcoding or hls transcoding' }) | ||
160 | return false | ||
161 | } | ||
162 | |||
163 | return true | ||
164 | } | ||
165 | |||
166 | function checkInvalidSynchronizationConfig (customConfig: CustomConfig, res: express.Response) { | ||
167 | if (customConfig.import.videoChannelSynchronization.enabled && !customConfig.import.videos.http.enabled) { | ||
168 | res.fail({ message: 'You need to enable HTTP video import in order to enable channel synchronization' }) | ||
169 | return false | ||
170 | } | ||
171 | return true | ||
172 | } | ||
173 | |||
174 | function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) { | ||
175 | if (customConfig.live.enabled === false) return true | ||
176 | |||
177 | if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) { | ||
178 | res.fail({ message: 'You cannot allow live replay if transcoding is not enabled' }) | ||
179 | return false | ||
180 | } | ||
181 | |||
182 | return true | ||
183 | } | ||
184 | |||
185 | function checkInvalidVideoStudioConfig (customConfig: CustomConfig, res: express.Response) { | ||
186 | if (customConfig.videoStudio.enabled === false) return true | ||
187 | |||
188 | if (customConfig.videoStudio.enabled === true && customConfig.transcoding.enabled === false) { | ||
189 | res.fail({ message: 'You cannot enable video studio if transcoding is not enabled' }) | ||
190 | return false | ||
191 | } | ||
192 | |||
193 | return true | ||
194 | } | ||