]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker-before-init.ts
Live supports object storage
[github/Chocobozzz/PeerTube.git] / server / initializers / checker-before-init.ts
CommitLineData
41fb13c3 1import { IConfig } from 'config'
ae71acca 2import { parseSemVersion, promisify0 } from '../helpers/core-utils'
51c35447 3import { logger } from '../helpers/logger'
9f10b292 4
41fb13c3
C
5// Special behaviour for config because we can reload it
6const config: IConfig = require('config')
7
e5565833 8// ONLY USE CORE MODULES IN THIS FILE!
b65c27aa
C
9
10// Check the config files
11function checkMissedConfig () {
cff8b272 12 const required = [ 'listen.port', 'listen.hostname',
3737bbaf 13 'webserver.https', 'webserver.hostname', 'webserver.port',
490b595a 14 'trust_proxy',
3a735f7d 15 'database.hostname', 'database.port', 'database.username', 'database.password', 'database.pool.max',
a465bf5f 16 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address',
916937d7 17 'email.body.signature', 'email.subject.prefix',
a465bf5f 18 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache',
345da516 19 'storage.redundancy', 'storage.tmp', 'storage.streaming_playlists', 'storage.plugins',
a465bf5f 20 'log.level',
bee0abff 21 'user.video_quota', 'user.video_quota_daily',
754b6f5f 22 'video_channels.max_per_user',
539d3f4f 23 'csp.enabled', 'csp.report_only', 'csp.report_uri',
8155db66 24 'security.frameguard.enabled',
90a8bd30 25 'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled',
1f256e7d 26 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', 'signup.minimum_age',
d9eaee39 27 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
f9f899b9 28 'redundancy.videos.strategies', 'redundancy.videos.check_interval',
5d9e4eaa 29 'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions', 'transcoding.hls.enabled',
9129b769 30 'transcoding.profile', 'transcoding.concurrency',
8dd754c7
FC
31 'transcoding.resolutions.0p', 'transcoding.resolutions.144p', 'transcoding.resolutions.240p', 'transcoding.resolutions.360p',
32 'transcoding.resolutions.480p', 'transcoding.resolutions.720p', 'transcoding.resolutions.1080p', 'transcoding.resolutions.1440p',
84cae54e 33 'transcoding.resolutions.2160p', 'transcoding.always_transcode_original_resolution', 'video_studio.enabled',
3eba7ab8 34 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'import.videos.timeout',
2a491182
F
35 'import.video_channel_synchronization.enabled', 'import.video_channel_synchronization.max_per_user',
36 'import.video_channel_synchronization.check_interval', 'import.video_channel_synchronization.videos_limit_per_synchronization',
3eba7ab8 37 'auto_blacklist.videos.of_users.enabled', 'trending.videos.interval_days',
2c102aac 38 'client.videos.miniature.display_author_avatar',
0bc53e20 39 'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth',
3cf68b86 40 'defaults.publish.download_enabled', 'defaults.publish.comments_enabled', 'defaults.publish.privacy', 'defaults.publish.licence',
0883b324 41 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
f8802489 42 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt',
5b9c965d 43 'services.twitter.username', 'services.twitter.whitelisted',
31b6ddf8 44 'followers.instance.enabled', 'followers.instance.manual_approval',
cda03765 45 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces',
51353d9a 46 'history.videos.max_age', 'views.videos.remote.max_age', 'views.videos.local_buffer_update_interval', 'views.videos.ip_view_expiration',
7cd4d2ba 47 'rates_limit.login.window', 'rates_limit.login.max', 'rates_limit.ask_send_email.window', 'rates_limit.ask_send_email.max',
8c9e7875 48 'theme.default',
600befbd 49 'feeds.videos.count', 'feeds.comments.count',
b2111066 50 'geo_ip.enabled', 'geo_ip.country.database_url',
3092e9bb 51 'remote_redundancy.videos.accept_from',
74d249bc 52 'federation.videos.federate_unlisted', 'federation.videos.cleanup_remote_interactions',
32a18cbf 53 'peertube.check_latest_version.enabled', 'peertube.check_latest_version.url',
5fb2e288 54 'search.remote_uri.users', 'search.remote_uri.anonymous', 'search.search_index.enabled', 'search.search_index.url',
fb719404 55 'search.search_index.disable_local_search', 'search.search_index.is_default_search',
f443a746 56 'live.enabled', 'live.allow_replay', 'live.latency_setting.enabled', 'live.max_duration',
d05af385
C
57 'live.max_user_lives', 'live.max_instance_lives',
58 'live.rtmp.enabled', 'live.rtmp.port', 'live.rtmp.hostname', 'live.rtmp.public_hostname',
59 'live.rtmps.enabled', 'live.rtmps.port', 'live.rtmps.hostname', 'live.rtmps.public_hostname',
60 'live.rtmps.key_file', 'live.rtmps.cert_file',
80ac2e55 61 'live.transcoding.enabled', 'live.transcoding.threads', 'live.transcoding.profile',
8dd754c7
FC
62 'live.transcoding.resolutions.144p', 'live.transcoding.resolutions.240p', 'live.transcoding.resolutions.360p',
63 'live.transcoding.resolutions.480p', 'live.transcoding.resolutions.720p', 'live.transcoding.resolutions.1080p',
84cae54e 64 'live.transcoding.resolutions.1440p', 'live.transcoding.resolutions.2160p', 'live.transcoding.always_transcode_original_resolution'
56835348 65 ]
fb719404 66
19f7b248
RK
67 const requiredAlternatives = [
68 [ // set
a1587156
C
69 [ 'redis.hostname', 'redis.port' ], // alternative
70 [ 'redis.socket' ]
19f7b248
RK
71 ]
72 ]
69818c93 73 const miss: string[] = []
9f10b292 74
f0f5567b 75 for (const key of required) {
9f10b292
C
76 if (!config.has(key)) {
77 miss.push(key)
8c308c2b 78 }
8c308c2b
C
79 }
80
e5565833 81 const redundancyVideos = config.get<any>('redundancy.videos.strategies')
d85798c4
C
82
83 if (Array.isArray(redundancyVideos)) {
e5565833
C
84 for (const r of redundancyVideos) {
85 if (!r.size) miss.push('redundancy.videos.strategies.size')
86 if (!r.min_lifetime) miss.push('redundancy.videos.strategies.min_lifetime')
87 }
88 }
89
19f7b248
RK
90 const missingAlternatives = requiredAlternatives.filter(
91 set => !set.find(alternative => !alternative.find(key => !config.has(key)))
92 )
93
94 missingAlternatives
95 .forEach(set => set[0].forEach(key => miss.push(key)))
96
9f10b292
C
97 return miss
98}
99
e5b88539 100// Check the available codecs
3482688c 101// We get CONFIG by param to not import it in this file (import orders)
f5028693 102async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
959dbbd7
C
103 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
104
e5b88539 105 const Ffmpeg = require('fluent-ffmpeg')
6fcd19ba 106 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
f5028693 107 const codecs = await getAvailableCodecsPromise()
4176e227
RK
108 const canEncode = [ 'libx264' ]
109
f5028693
C
110 for (const codec of canEncode) {
111 if (codecs[codec] === undefined) {
112 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
113 }
114
115 if (codecs[codec].canEncode !== true) {
116 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
117 }
118 }
e5b88539
C
119}
120
51c35447
C
121function checkNodeVersion () {
122 const v = process.version
ae71acca 123 const { major } = parseSemVersion(v)
51c35447
C
124
125 logger.debug('Checking NodeJS version %s.', v)
126
4ff75a3b 127 if (major <= 12) {
90fbb784 128 throw new Error('Your NodeJS version ' + v + ' is not supported. Please upgrade.')
4ff75a3b 129 }
51c35447
C
130}
131
9f10b292 132// ---------------------------------------------------------------------------
c45f7f84 133
65fcc311 134export {
65fcc311 135 checkFFmpeg,
51c35447
C
136 checkMissedConfig,
137 checkNodeVersion
65fcc311 138}