]>
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 | ||
c729caf6 C |
45 | checkEmailConfig() |
46 | checkNSFWPolicyConfig() | |
47 | checkLocalRedundancyConfig() | |
48 | checkRemoteRedundancyConfig() | |
49 | checkStorageConfig() | |
50 | checkTranscodingConfig() | |
2a491182 | 51 | checkImportConfig() |
c729caf6 C |
52 | checkBroadcastMessageConfig() |
53 | checkSearchConfig() | |
54 | checkLiveConfig() | |
55 | checkObjectStorageConfig() | |
92e66e04 | 56 | checkVideoStudioConfig() |
c729caf6 C |
57 | } |
58 | ||
59 | // We get db by param to not import it in this file (import orders) | |
60 | async function clientsExist () { | |
61 | const totalClients = await OAuthClientModel.countTotal() | |
62 | ||
63 | return totalClients !== 0 | |
64 | } | |
65 | ||
66 | // We get db by param to not import it in this file (import orders) | |
67 | async function usersExist () { | |
68 | const totalUsers = await UserModel.countTotal() | |
69 | ||
70 | return totalUsers !== 0 | |
71 | } | |
72 | ||
73 | // We get db by param to not import it in this file (import orders) | |
74 | async function applicationExist () { | |
75 | const totalApplication = await ApplicationModel.countTotal() | |
76 | ||
77 | return totalApplication !== 0 | |
78 | } | |
79 | ||
80 | async function checkFFmpegVersion () { | |
81 | const version = await getFFmpegVersion() | |
1efad362 | 82 | const { major, minor, patch } = parseSemVersion(version) |
c729caf6 C |
83 | |
84 | if (major < 4 || (major === 4 && minor < 1)) { | |
1efad362 C |
85 | logger.warn('Your ffmpeg version (%s) is outdated. PeerTube supports ffmpeg >= 4.1. Please upgrade ffmpeg.', version) |
86 | } | |
87 | ||
88 | if (major === 4 && minor === 4 && patch === 0) { | |
89 | logger.warn('There is a bug in ffmpeg 4.4.0 with HLS videos. Please upgrade ffmpeg.') | |
c729caf6 C |
90 | } |
91 | } | |
92 | ||
93 | // --------------------------------------------------------------------------- | |
94 | ||
95 | export { | |
96 | checkConfig, | |
97 | clientsExist, | |
98 | checkFFmpegVersion, | |
99 | usersExist, | |
100 | applicationExist, | |
101 | checkActivityPubUrls | |
102 | } | |
103 | ||
104 | // --------------------------------------------------------------------------- | |
105 | ||
106 | function checkEmailConfig () { | |
4c1c1709 | 107 | if (!isEmailEnabled()) { |
d3e56c0c | 108 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { |
c729caf6 | 109 | throw new Error('Emailer is disabled but you require signup email verification.') |
d3e56c0c C |
110 | } |
111 | ||
112 | if (CONFIG.CONTACT_FORM.ENABLED) { | |
113 | logger.warn('Emailer is disabled so the contact form will not work.') | |
114 | } | |
115 | } | |
c729caf6 | 116 | } |
e5565833 | 117 | |
c729caf6 | 118 | function checkNSFWPolicyConfig () { |
d3e56c0c | 119 | const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY |
c729caf6 C |
120 | |
121 | const available = [ 'do_not_list', 'blur', 'display' ] | |
122 | if (available.includes(defaultNSFWPolicy) === false) { | |
123 | throw new Error('NSFW policy setting should be ' + available.join(' or ') + ' instead of ' + defaultNSFWPolicy) | |
e5565833 | 124 | } |
c729caf6 | 125 | } |
e5565833 | 126 | |
c729caf6 | 127 | function checkLocalRedundancyConfig () { |
e5565833 | 128 | const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES |
c729caf6 | 129 | |
e5565833 C |
130 | if (isArray(redundancyVideos)) { |
131 | const available = [ 'most-views', 'trending', 'recently-added' ] | |
c729caf6 | 132 | |
e5565833 | 133 | for (const r of redundancyVideos) { |
bdd428a6 | 134 | if (available.includes(r.strategy) === false) { |
c729caf6 | 135 | throw new Error('Videos redundancy should have ' + available.join(' or ') + ' strategy instead of ' + r.strategy) |
e5565833 C |
136 | } |
137 | ||
138 | // Lifetime should not be < 10 hours | |
9452d4fd | 139 | if (isProdInstance() && r.minLifetime < 1000 * 3600 * 10) { |
c729caf6 | 140 | throw new Error('Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy) |
e5565833 C |
141 | } |
142 | } | |
143 | ||
690bb8f9 | 144 | const filtered = uniqify(redundancyVideos.map(r => r.strategy)) |
e5565833 | 145 | if (filtered.length !== redundancyVideos.length) { |
c729caf6 | 146 | throw new Error('Redundancy video entries should have unique strategies') |
e5565833 C |
147 | } |
148 | ||
149 | const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy | |
150 | if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { | |
c729caf6 | 151 | throw new Error('Min views in recently added strategy is not a number') |
e5565833 | 152 | } |
d85798c4 | 153 | } else { |
c729caf6 | 154 | throw new Error('Videos redundancy should be an array (you must uncomment lines containing - too)') |
e5565833 | 155 | } |
c729caf6 | 156 | } |
e5565833 | 157 | |
c729caf6 | 158 | function checkRemoteRedundancyConfig () { |
8c9e7875 C |
159 | const acceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM |
160 | const acceptFromValues = new Set<VideoRedundancyConfigFilter>([ 'nobody', 'anybody', 'followings' ]) | |
c729caf6 | 161 | |
8c9e7875 | 162 | if (acceptFromValues.has(acceptFrom) === false) { |
c729caf6 | 163 | throw new Error('remote_redundancy.videos.accept_from has an incorrect value') |
8c9e7875 | 164 | } |
c729caf6 | 165 | } |
8c9e7875 | 166 | |
c729caf6 | 167 | function checkStorageConfig () { |
d3e56c0c | 168 | // Check storage directory locations |
e5565833 | 169 | if (isProdInstance()) { |
d41a3805 | 170 | const configStorage = config.get('storage') |
e5565833 C |
171 | for (const key of Object.keys(configStorage)) { |
172 | if (configStorage[key].startsWith('storage/')) { | |
173 | logger.warn( | |
174 | 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.', | |
175 | key | |
176 | ) | |
177 | } | |
178 | } | |
179 | } | |
180 | ||
72c33e71 C |
181 | if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) { |
182 | logger.warn('Redundancy directory should be different than the videos folder.') | |
183 | } | |
c729caf6 | 184 | } |
72c33e71 | 185 | |
c729caf6 | 186 | function checkTranscodingConfig () { |
d7a25329 C |
187 | if (CONFIG.TRANSCODING.ENABLED) { |
188 | if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) { | |
c729caf6 | 189 | throw new Error('You need to enable at least WebTorrent transcoding or HLS transcoding.') |
d7a25329 | 190 | } |
9129b769 C |
191 | |
192 | if (CONFIG.TRANSCODING.CONCURRENCY <= 0) { | |
c729caf6 | 193 | throw new Error('Transcoding concurrency should be > 0') |
9129b769 C |
194 | } |
195 | } | |
196 | ||
197 | if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED || CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED) { | |
198 | if (CONFIG.IMPORT.VIDEOS.CONCURRENCY <= 0) { | |
c729caf6 | 199 | throw new Error('Video import concurrency should be > 0') |
9129b769 | 200 | } |
d7a25329 | 201 | } |
c729caf6 | 202 | } |
d7a25329 | 203 | |
2a491182 F |
204 | function checkImportConfig () { |
205 | if (CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.ENABLED && !CONFIG.IMPORT.VIDEOS.HTTP) { | |
206 | throw new Error('You need to enable HTTP import to allow synchronization') | |
207 | } | |
208 | } | |
209 | ||
c729caf6 | 210 | function checkBroadcastMessageConfig () { |
72c33e71 C |
211 | if (CONFIG.BROADCAST_MESSAGE.ENABLED) { |
212 | const currentLevel = CONFIG.BROADCAST_MESSAGE.LEVEL | |
31a91119 | 213 | const available = [ 'info', 'warning', 'error' ] |
72c33e71 C |
214 | |
215 | if (available.includes(currentLevel) === false) { | |
c729caf6 | 216 | throw new Error('Broadcast message level should be ' + available.join(' or ') + ' instead of ' + currentLevel) |
72c33e71 | 217 | } |
2034c3aa | 218 | } |
c729caf6 | 219 | } |
2034c3aa | 220 | |
c729caf6 | 221 | function checkSearchConfig () { |
5fb2e288 C |
222 | if (CONFIG.SEARCH.SEARCH_INDEX.ENABLED === true) { |
223 | if (CONFIG.SEARCH.REMOTE_URI.USERS === false) { | |
c729caf6 | 224 | throw new Error('You cannot enable search index without enabling remote URI search for users.') |
5fb2e288 C |
225 | } |
226 | } | |
c729caf6 | 227 | } |
5fb2e288 | 228 | |
c729caf6 | 229 | function checkLiveConfig () { |
fb719404 C |
230 | if (CONFIG.LIVE.ENABLED === true) { |
231 | if (CONFIG.LIVE.ALLOW_REPLAY === true && CONFIG.TRANSCODING.ENABLED === false) { | |
c729caf6 | 232 | throw new Error('Live allow replay cannot be enabled if transcoding is not enabled.') |
fb719404 | 233 | } |
df1db951 C |
234 | |
235 | if (CONFIG.LIVE.RTMP.ENABLED === false && CONFIG.LIVE.RTMPS.ENABLED === false) { | |
c729caf6 | 236 | throw new Error('You must enable at least RTMP or RTMPS') |
df1db951 C |
237 | } |
238 | ||
239 | if (CONFIG.LIVE.RTMPS.ENABLED) { | |
240 | if (!CONFIG.LIVE.RTMPS.KEY_FILE) { | |
c729caf6 | 241 | throw new Error('You must specify a key file to enabled RTMPS') |
df1db951 C |
242 | } |
243 | ||
244 | if (!CONFIG.LIVE.RTMPS.CERT_FILE) { | |
c729caf6 | 245 | throw new Error('You must specify a cert file to enable RTMPS') |
df1db951 C |
246 | } |
247 | } | |
fb719404 | 248 | } |
c729caf6 | 249 | } |
fb719404 | 250 | |
c729caf6 | 251 | function checkObjectStorageConfig () { |
0305db28 JB |
252 | if (CONFIG.OBJECT_STORAGE.ENABLED === true) { |
253 | ||
254 | if (!CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME) { | |
c729caf6 | 255 | throw new Error('videos_bucket should be set when object storage support is enabled.') |
0305db28 JB |
256 | } |
257 | ||
258 | if (!CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME) { | |
c729caf6 | 259 | throw new Error('streaming_playlists_bucket should be set when object storage support is enabled.') |
0305db28 JB |
260 | } |
261 | ||
262 | if ( | |
263 | CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME && | |
264 | CONFIG.OBJECT_STORAGE.VIDEOS.PREFIX === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.PREFIX | |
265 | ) { | |
266 | if (CONFIG.OBJECT_STORAGE.VIDEOS.PREFIX === '') { | |
c729caf6 | 267 | throw new Error('Object storage bucket prefixes should be set when the same bucket is used for both types of video.') |
0305db28 | 268 | } |
c729caf6 C |
269 | |
270 | throw new Error( | |
271 | 'Object storage bucket prefixes should be set to different values when the same bucket is used for both types of video.' | |
272 | ) | |
0305db28 JB |
273 | } |
274 | } | |
e5565833 C |
275 | } |
276 | ||
92e66e04 C |
277 | function checkVideoStudioConfig () { |
278 | if (CONFIG.VIDEO_STUDIO.ENABLED === true && CONFIG.TRANSCODING.ENABLED === false) { | |
279 | throw new Error('Video studio cannot be enabled if transcoding is disabled') | |
ae71acca C |
280 | } |
281 | } |