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