]>
Commit | Line | Data |
---|---|---|
d41a3805 | 1 | import config from 'config' |
ae71acca | 2 | import { uniq } from 'lodash' |
a1587156 | 3 | import { URL } from 'url' |
ae71acca C |
4 | import { getFFmpegVersion } from '@server/helpers/ffmpeg-utils' |
5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' | |
d1105b97 | 6 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' |
ae71acca | 7 | import { isProdInstance, isTestInstance, 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 | ||
34 | // Some checks on configuration files | |
35 | // Return an error message, or null if everything is okay | |
36 | function checkConfig () { | |
d3e56c0c | 37 | |
539d3f4f | 38 | // Moved configuration keys |
d41a3805 | 39 | if (config.has('services.csp-logger')) { |
539d3f4f C |
40 | logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.') |
41 | } | |
42 | ||
43 | // Email verification | |
4c1c1709 | 44 | if (!isEmailEnabled()) { |
d3e56c0c C |
45 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { |
46 | return 'Emailer is disabled but you require signup email verification.' | |
47 | } | |
48 | ||
49 | if (CONFIG.CONTACT_FORM.ENABLED) { | |
50 | logger.warn('Emailer is disabled so the contact form will not work.') | |
51 | } | |
52 | } | |
e5565833 C |
53 | |
54 | // NSFW policy | |
d3e56c0c | 55 | const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY |
e5565833 C |
56 | { |
57 | const available = [ 'do_not_list', 'blur', 'display' ] | |
bdd428a6 | 58 | if (available.includes(defaultNSFWPolicy) === false) { |
e5565833 C |
59 | return 'NSFW policy setting should be ' + available.join(' or ') + ' instead of ' + defaultNSFWPolicy |
60 | } | |
61 | } | |
62 | ||
63 | // Redundancies | |
64 | const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES | |
65 | if (isArray(redundancyVideos)) { | |
66 | const available = [ 'most-views', 'trending', 'recently-added' ] | |
67 | for (const r of redundancyVideos) { | |
bdd428a6 | 68 | if (available.includes(r.strategy) === false) { |
e5565833 C |
69 | return 'Videos redundancy should have ' + available.join(' or ') + ' strategy instead of ' + r.strategy |
70 | } | |
71 | ||
72 | // Lifetime should not be < 10 hours | |
73 | if (!isTestInstance() && r.minLifetime < 1000 * 3600 * 10) { | |
74 | return 'Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy | |
75 | } | |
76 | } | |
77 | ||
78 | const filtered = uniq(redundancyVideos.map(r => r.strategy)) | |
79 | if (filtered.length !== redundancyVideos.length) { | |
80 | return 'Redundancy video entries should have unique strategies' | |
81 | } | |
82 | ||
83 | const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy | |
84 | if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { | |
85 | return 'Min views in recently added strategy is not a number' | |
86 | } | |
d85798c4 C |
87 | } else { |
88 | return 'Videos redundancy should be an array (you must uncomment lines containing - too)' | |
e5565833 C |
89 | } |
90 | ||
8c9e7875 C |
91 | // Remote redundancies |
92 | const acceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM | |
93 | const acceptFromValues = new Set<VideoRedundancyConfigFilter>([ 'nobody', 'anybody', 'followings' ]) | |
94 | if (acceptFromValues.has(acceptFrom) === false) { | |
95 | return 'remote_redundancy.videos.accept_from has an incorrect value' | |
96 | } | |
97 | ||
d3e56c0c | 98 | // Check storage directory locations |
e5565833 | 99 | if (isProdInstance()) { |
d41a3805 | 100 | const configStorage = config.get('storage') |
e5565833 C |
101 | for (const key of Object.keys(configStorage)) { |
102 | if (configStorage[key].startsWith('storage/')) { | |
103 | logger.warn( | |
104 | 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.', | |
105 | key | |
106 | ) | |
107 | } | |
108 | } | |
109 | } | |
110 | ||
72c33e71 C |
111 | if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) { |
112 | logger.warn('Redundancy directory should be different than the videos folder.') | |
113 | } | |
114 | ||
d7a25329 C |
115 | // Transcoding |
116 | if (CONFIG.TRANSCODING.ENABLED) { | |
117 | if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) { | |
118 | return 'You need to enable at least WebTorrent transcoding or HLS transcoding.' | |
119 | } | |
9129b769 C |
120 | |
121 | if (CONFIG.TRANSCODING.CONCURRENCY <= 0) { | |
122 | return 'Transcoding concurrency should be > 0' | |
123 | } | |
124 | } | |
125 | ||
126 | if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED || CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED) { | |
127 | if (CONFIG.IMPORT.VIDEOS.CONCURRENCY <= 0) { | |
128 | return 'Video import concurrency should be > 0' | |
129 | } | |
d7a25329 C |
130 | } |
131 | ||
72c33e71 C |
132 | // Broadcast message |
133 | if (CONFIG.BROADCAST_MESSAGE.ENABLED) { | |
134 | const currentLevel = CONFIG.BROADCAST_MESSAGE.LEVEL | |
31a91119 | 135 | const available = [ 'info', 'warning', 'error' ] |
72c33e71 C |
136 | |
137 | if (available.includes(currentLevel) === false) { | |
138 | return 'Broadcast message level should be ' + available.join(' or ') + ' instead of ' + currentLevel | |
139 | } | |
2034c3aa C |
140 | } |
141 | ||
5fb2e288 C |
142 | // Search index |
143 | if (CONFIG.SEARCH.SEARCH_INDEX.ENABLED === true) { | |
144 | if (CONFIG.SEARCH.REMOTE_URI.USERS === false) { | |
145 | return 'You cannot enable search index without enabling remote URI search for users.' | |
146 | } | |
147 | } | |
148 | ||
fb719404 C |
149 | // Live |
150 | if (CONFIG.LIVE.ENABLED === true) { | |
151 | if (CONFIG.LIVE.ALLOW_REPLAY === true && CONFIG.TRANSCODING.ENABLED === false) { | |
152 | return 'Live allow replay cannot be enabled if transcoding is not enabled.' | |
153 | } | |
df1db951 C |
154 | |
155 | if (CONFIG.LIVE.RTMP.ENABLED === false && CONFIG.LIVE.RTMPS.ENABLED === false) { | |
156 | return 'You must enable at least RTMP or RTMPS' | |
157 | } | |
158 | ||
159 | if (CONFIG.LIVE.RTMPS.ENABLED) { | |
160 | if (!CONFIG.LIVE.RTMPS.KEY_FILE) { | |
161 | return 'You must specify a key file to enabled RTMPS' | |
162 | } | |
163 | ||
164 | if (!CONFIG.LIVE.RTMPS.CERT_FILE) { | |
165 | return 'You must specify a cert file to enable RTMPS' | |
166 | } | |
167 | } | |
fb719404 C |
168 | } |
169 | ||
0305db28 JB |
170 | // Object storage |
171 | if (CONFIG.OBJECT_STORAGE.ENABLED === true) { | |
172 | ||
173 | if (!CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME) { | |
174 | return 'videos_bucket should be set when object storage support is enabled.' | |
175 | } | |
176 | ||
177 | if (!CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME) { | |
178 | return 'streaming_playlists_bucket should be set when object storage support is enabled.' | |
179 | } | |
180 | ||
181 | if ( | |
182 | CONFIG.OBJECT_STORAGE.VIDEOS.BUCKET_NAME === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME && | |
183 | CONFIG.OBJECT_STORAGE.VIDEOS.PREFIX === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.PREFIX | |
184 | ) { | |
185 | if (CONFIG.OBJECT_STORAGE.VIDEOS.PREFIX === '') { | |
186 | return 'Object storage bucket prefixes should be set when the same bucket is used for both types of video.' | |
187 | } else { | |
188 | return 'Object storage bucket prefixes should be set to different values when the same bucket is used for both types of video.' | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
e5565833 C |
193 | return null |
194 | } | |
195 | ||
196 | // We get db by param to not import it in this file (import orders) | |
197 | async function clientsExist () { | |
198 | const totalClients = await OAuthClientModel.countTotal() | |
199 | ||
200 | return totalClients !== 0 | |
201 | } | |
202 | ||
203 | // We get db by param to not import it in this file (import orders) | |
204 | async function usersExist () { | |
205 | const totalUsers = await UserModel.countTotal() | |
206 | ||
207 | return totalUsers !== 0 | |
208 | } | |
209 | ||
210 | // We get db by param to not import it in this file (import orders) | |
211 | async function applicationExist () { | |
212 | const totalApplication = await ApplicationModel.countTotal() | |
213 | ||
214 | return totalApplication !== 0 | |
215 | } | |
216 | ||
ae71acca C |
217 | async function checkFFmpegVersion () { |
218 | const version = await getFFmpegVersion() | |
219 | const { major, minor } = parseSemVersion(version) | |
220 | ||
221 | if (major < 4 || (major === 4 && minor < 1)) { | |
222 | logger.warn('Your ffmpeg version (%s) is outdated. PeerTube supports ffmpeg >= 4.1. Please upgrade.', version) | |
223 | } | |
224 | } | |
225 | ||
e5565833 C |
226 | // --------------------------------------------------------------------------- |
227 | ||
228 | export { | |
229 | checkConfig, | |
230 | clientsExist, | |
ae71acca | 231 | checkFFmpegVersion, |
e5565833 C |
232 | usersExist, |
233 | applicationExist, | |
234 | checkActivityPubUrls | |
235 | } |