]>
Commit | Line | Data |
---|---|---|
d41a3805 | 1 | import config from 'config' |
a1587156 | 2 | import { URL } from 'url' |
c729caf6 | 3 | import { getFFmpegVersion } from '@server/helpers/ffmpeg' |
690bb8f9 | 4 | import { uniqify } from '@shared/core-utils' |
ae71acca | 5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' |
d1105b97 | 6 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' |
9452d4fd | 7 | import { isProdInstance, parseSemVersion } from '../helpers/core-utils' |
e5565833 | 8 | import { isArray } from '../helpers/custom-validators/misc' |
ae71acca | 9 | import { logger } from '../helpers/logger' |
ae71acca C |
10 | import { ApplicationModel, getServerActor } from '../models/application/application' |
11 | import { OAuthClientModel } from '../models/oauth/oauth-client' | |
d41a3805 | 12 | import { UserModel } from '../models/user/user' |
ae71acca | 13 | import { CONFIG, isEmailEnabled } from './config' |
6dd9de95 | 14 | import { WEBSERVER } from './constants' |
e5565833 C |
15 | |
16 | async function checkActivityPubUrls () { | |
17 | const actor = await getServerActor() | |
18 | ||
a1587156 | 19 | const parsed = new URL(actor.url) |
6dd9de95 | 20 | if (WEBSERVER.HOST !== parsed.host) { |
d41a3805 C |
21 | const NODE_ENV = config.util.getEnv('NODE_ENV') |
22 | const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR') | |
e5565833 C |
23 | |
24 | logger.warn( | |
25 | 'It seems PeerTube was started (and created some data) with another domain name. ' + | |
26 | 'This means you will not be able to federate! ' + | |
27 | 'Please use %s %s npm run update-host to fix this.', | |
28 | NODE_CONFIG_DIR ? `NODE_CONFIG_DIR=${NODE_CONFIG_DIR}` : '', | |
29 | NODE_ENV ? `NODE_ENV=${NODE_ENV}` : '' | |
30 | ) | |
31 | } | |
32 | } | |
33 | ||
c729caf6 | 34 | // Some checks on configuration files or throw if there is an error |
e5565833 | 35 | function checkConfig () { |
d3e56c0c | 36 | |
9452d4fd C |
37 | const configFiles = config.util.getConfigSources().map(s => s.name).join(' -> ') |
38 | logger.info('Using following configuration file hierarchy: %s.', configFiles) | |
39 | ||
539d3f4f | 40 | // Moved configuration keys |
d41a3805 | 41 | if (config.has('services.csp-logger')) { |
539d3f4f C |
42 | logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.') |
43 | } | |
44 | ||
a3e5f804 | 45 | checkSecretsConfig() |
c729caf6 C |
46 | checkEmailConfig() |
47 | checkNSFWPolicyConfig() | |
48 | checkLocalRedundancyConfig() | |
49 | checkRemoteRedundancyConfig() | |
50 | checkStorageConfig() | |
51 | checkTranscodingConfig() | |
2a491182 | 52 | checkImportConfig() |
c729caf6 C |
53 | checkBroadcastMessageConfig() |
54 | checkSearchConfig() | |
55 | checkLiveConfig() | |
56 | checkObjectStorageConfig() | |
92e66e04 | 57 | checkVideoStudioConfig() |
c729caf6 C |
58 | } |
59 | ||
60 | // We get db by param to not import it in this file (import orders) | |
61 | async function clientsExist () { | |
62 | const totalClients = await OAuthClientModel.countTotal() | |
63 | ||
64 | return totalClients !== 0 | |
65 | } | |
66 | ||
67 | // We get db by param to not import it in this file (import orders) | |
68 | async function usersExist () { | |
69 | const totalUsers = await UserModel.countTotal() | |
70 | ||
71 | return totalUsers !== 0 | |
72 | } | |
73 | ||
74 | // We get db by param to not import it in this file (import orders) | |
75 | async function applicationExist () { | |
76 | const totalApplication = await ApplicationModel.countTotal() | |
77 | ||
78 | return totalApplication !== 0 | |
79 | } | |
80 | ||
81 | async function checkFFmpegVersion () { | |
82 | const version = await getFFmpegVersion() | |
1efad362 | 83 | const { major, minor, patch } = parseSemVersion(version) |
c729caf6 C |
84 | |
85 | if (major < 4 || (major === 4 && minor < 1)) { | |
1efad362 C |
86 | logger.warn('Your ffmpeg version (%s) is outdated. PeerTube supports ffmpeg >= 4.1. Please upgrade ffmpeg.', version) |
87 | } | |
88 | ||
89 | if (major === 4 && minor === 4 && patch === 0) { | |
90 | logger.warn('There is a bug in ffmpeg 4.4.0 with HLS videos. Please upgrade ffmpeg.') | |
c729caf6 C |
91 | } |
92 | } | |
93 | ||
94 | // --------------------------------------------------------------------------- | |
95 | ||
96 | export { | |
97 | checkConfig, | |
98 | clientsExist, | |
99 | checkFFmpegVersion, | |
100 | usersExist, | |
101 | applicationExist, | |
102 | checkActivityPubUrls | |
103 | } | |
104 | ||
105 | // --------------------------------------------------------------------------- | |
106 | ||
a3e5f804 C |
107 | function checkSecretsConfig () { |
108 | if (!CONFIG.SECRETS.PEERTUBE) { | |
109 | throw new Error('secrets.peertube is missing in config. Generate one using `openssl rand -hex 32`') | |
110 | } | |
111 | } | |
112 | ||
c729caf6 | 113 | function checkEmailConfig () { |
4c1c1709 | 114 | if (!isEmailEnabled()) { |
d3e56c0c | 115 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { |
c729caf6 | 116 | throw new Error('Emailer is disabled but you require signup email verification.') |
d3e56c0c C |
117 | } |
118 | ||
e364e31e C |
119 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_APPROVAL) { |
120 | // eslint-disable-next-line max-len | |
121 | logger.warn('Emailer is disabled but signup approval is enabled: PeerTube will not be able to send an email to the user upon acceptance/rejection of the registration request') | |
122 | } | |
123 | ||
d3e56c0c C |
124 | if (CONFIG.CONTACT_FORM.ENABLED) { |
125 | logger.warn('Emailer is disabled so the contact form will not work.') | |
126 | } | |
127 | } | |
c729caf6 | 128 | } |
e5565833 | 129 | |
c729caf6 | 130 | function checkNSFWPolicyConfig () { |
d3e56c0c | 131 | const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY |
c729caf6 C |
132 | |
133 | const available = [ 'do_not_list', 'blur', 'display' ] | |
134 | if (available.includes(defaultNSFWPolicy) === false) { | |
135 | throw new Error('NSFW policy setting should be ' + available.join(' or ') + ' instead of ' + defaultNSFWPolicy) | |
e5565833 | 136 | } |
c729caf6 | 137 | } |
e5565833 | 138 | |
c729caf6 | 139 | function checkLocalRedundancyConfig () { |
e5565833 | 140 | const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES |
c729caf6 | 141 | |
e5565833 C |
142 | if (isArray(redundancyVideos)) { |
143 | const available = [ 'most-views', 'trending', 'recently-added' ] | |
c729caf6 | 144 | |
e5565833 | 145 | for (const r of redundancyVideos) { |
bdd428a6 | 146 | if (available.includes(r.strategy) === false) { |
c729caf6 | 147 | throw new Error('Videos redundancy should have ' + available.join(' or ') + ' strategy instead of ' + r.strategy) |
e5565833 C |
148 | } |
149 | ||
150 | // Lifetime should not be < 10 hours | |
9452d4fd | 151 | if (isProdInstance() && r.minLifetime < 1000 * 3600 * 10) { |
c729caf6 | 152 | throw new Error('Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy) |
e5565833 C |
153 | } |
154 | } | |
155 | ||
690bb8f9 | 156 | const filtered = uniqify(redundancyVideos.map(r => r.strategy)) |
e5565833 | 157 | if (filtered.length !== redundancyVideos.length) { |
c729caf6 | 158 | throw new Error('Redundancy video entries should have unique strategies') |
e5565833 C |
159 | } |
160 | ||
161 | const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy | |
162 | if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { | |
c729caf6 | 163 | throw new Error('Min views in recently added strategy is not a number') |
e5565833 | 164 | } |
d85798c4 | 165 | } else { |
c729caf6 | 166 | throw new Error('Videos redundancy should be an array (you must uncomment lines containing - too)') |
e5565833 | 167 | } |
c729caf6 | 168 | } |
e5565833 | 169 | |
c729caf6 | 170 | function checkRemoteRedundancyConfig () { |
8c9e7875 C |
171 | const acceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM |
172 | const acceptFromValues = new Set<VideoRedundancyConfigFilter>([ 'nobody', 'anybody', 'followings' ]) | |
c729caf6 | 173 | |
8c9e7875 | 174 | if (acceptFromValues.has(acceptFrom) === false) { |
c729caf6 | 175 | throw new Error('remote_redundancy.videos.accept_from has an incorrect value') |
8c9e7875 | 176 | } |
c729caf6 | 177 | } |
8c9e7875 | 178 | |
c729caf6 | 179 | function checkStorageConfig () { |
d3e56c0c | 180 | // Check storage directory locations |
e5565833 | 181 | if (isProdInstance()) { |
60b880ac C |
182 | const configStorage = config.get<{ [ name: string ]: string }>('storage') |
183 | ||
e5565833 C |
184 | for (const key of Object.keys(configStorage)) { |
185 | if (configStorage[key].startsWith('storage/')) { | |
186 | logger.warn( | |
187 | 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.', | |
188 | key | |
189 | ) | |
190 | } | |
191 | } | |
192 | } | |
193 | ||
72c33e71 C |
194 | if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) { |
195 | logger.warn('Redundancy directory should be different than the videos folder.') | |
196 | } | |
c729caf6 | 197 | } |
72c33e71 | 198 | |
c729caf6 | 199 | function checkTranscodingConfig () { |
d7a25329 C |
200 | if (CONFIG.TRANSCODING.ENABLED) { |
201 | if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) { | |
c729caf6 | 202 | throw new Error('You need to enable at least WebTorrent transcoding or HLS transcoding.') |
d7a25329 | 203 | } |
9129b769 C |
204 | |
205 | if (CONFIG.TRANSCODING.CONCURRENCY <= 0) { | |
c729caf6 | 206 | throw new Error('Transcoding concurrency should be > 0') |
9129b769 C |
207 | } |
208 | } | |
209 | ||
210 | if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED || CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED) { | |
211 | if (CONFIG.IMPORT.VIDEOS.CONCURRENCY <= 0) { | |
c729caf6 | 212 | throw new Error('Video import concurrency should be > 0') |
9129b769 | 213 | } |
d7a25329 | 214 | } |
c729caf6 | 215 | } |
d7a25329 | 216 | |
2a491182 F |
217 | function checkImportConfig () { |
218 | if (CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED && !CONFIG.IMPORT.VIDEOS.HTTP) { | |
219 | throw new Error('You need to enable HTTP import to allow synchronization') | |
220 | } | |
221 | } | |
222 | ||
c729caf6 | 223 | function checkBroadcastMessageConfig () { |
72c33e71 C |
224 | if (CONFIG.BROADCAST_MESSAGE.ENABLED) { |
225 | const currentLevel = CONFIG.BROADCAST_MESSAGE.LEVEL | |
31a91119 | 226 | const available = [ 'info', 'warning', 'error' ] |
72c33e71 C |
227 | |
228 | if (available.includes(currentLevel) === false) { | |
c729caf6 | 229 | throw new Error('Broadcast message level should be ' + available.join(' or ') + ' instead of ' + currentLevel) |
72c33e71 | 230 | } |
2034c3aa | 231 | } |
c729caf6 | 232 | } |
2034c3aa | 233 | |
c729caf6 | 234 | function checkSearchConfig () { |
5fb2e288 C |
235 | if (CONFIG.SEARCH.SEARCH_INDEX.ENABLED === true) { |
236 | if (CONFIG.SEARCH.REMOTE_URI.USERS === false) { | |
c729caf6 | 237 | throw new Error('You cannot enable search index without enabling remote URI search for users.') |
5fb2e288 C |
238 | } |
239 | } | |
c729caf6 | 240 | } |
5fb2e288 | 241 | |
c729caf6 | 242 | function checkLiveConfig () { |
fb719404 C |
243 | if (CONFIG.LIVE.ENABLED === true) { |
244 | if (CONFIG.LIVE.ALLOW_REPLAY === true && CONFIG.TRANSCODING.ENABLED === false) { | |
c729caf6 | 245 | throw new Error('Live allow replay cannot be enabled if transcoding is not enabled.') |
fb719404 | 246 | } |
df1db951 C |
247 | |
248 | if (CONFIG.LIVE.RTMP.ENABLED === false && CONFIG.LIVE.RTMPS.ENABLED === false) { | |
c729caf6 | 249 | throw new Error('You must enable at least RTMP or RTMPS') |
df1db951 C |
250 | } |
251 | ||
252 | if (CONFIG.LIVE.RTMPS.ENABLED) { | |
253 | if (!CONFIG.LIVE.RTMPS.KEY_FILE) { | |
c729caf6 | 254 | throw new Error('You must specify a key file to enabled RTMPS') |
df1db951 C |
255 | } |
256 | ||
257 | if (!CONFIG.LIVE.RTMPS.CERT_FILE) { | |
c729caf6 | 258 | throw new Error('You must specify a cert file to enable RTMPS') |
df1db951 C |
259 | } |
260 | } | |
fb719404 | 261 | } |
c729caf6 | 262 | } |
fb719404 | 263 | |
c729caf6 | 264 | function checkObjectStorageConfig () { |
0305db28 JB |
265 | if (CONFIG.OBJECT_STORAGE.ENABLED === true) { |
266 | ||
267 | if (!CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME) { | |
c729caf6 | 268 | throw new Error('videos_bucket should be set when object storage support is enabled.') |
0305db28 JB |
269 | } |
270 | ||
271 | if (!CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME) { | |
c729caf6 | 272 | throw new Error('streaming_playlists_bucket should be set when object storage support is enabled.') |
0305db28 JB |
273 | } |
274 | ||
275 | if ( | |
276 | CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME && | |
277 | CONFIG.OBJECT_STORAGE.VIDEOS.PREFIX === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.PREFIX | |
278 | ) { | |
279 | if (CONFIG.OBJECT_STORAGE.VIDEOS.PREFIX === '') { | |
c729caf6 | 280 | throw new Error('Object storage bucket prefixes should be set when the same bucket is used for both types of video.') |
0305db28 | 281 | } |
c729caf6 C |
282 | |
283 | throw new Error( | |
284 | 'Object storage bucket prefixes should be set to different values when the same bucket is used for both types of video.' | |
285 | ) | |
0305db28 JB |
286 | } |
287 | } | |
e5565833 C |
288 | } |
289 | ||
92e66e04 C |
290 | function checkVideoStudioConfig () { |
291 | if (CONFIG.VIDEO_STUDIO.ENABLED === true && CONFIG.TRANSCODING.ENABLED === false) { | |
292 | throw new Error('Video studio cannot be enabled if transcoding is disabled') | |
ae71acca C |
293 | } |
294 | } |