]>
Commit | Line | Data |
---|---|---|
1 | import * as config from 'config' | |
2 | import { promisify0 } from '../helpers/core-utils' | |
3 | import { logger } from '../helpers/logger' | |
4 | ||
5 | // ONLY USE CORE MODULES IN THIS FILE! | |
6 | ||
7 | // Check the config files | |
8 | function checkMissedConfig () { | |
9 | const required = [ 'listen.port', 'listen.hostname', | |
10 | 'webserver.https', 'webserver.hostname', 'webserver.port', | |
11 | 'trust_proxy', | |
12 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', 'database.pool.max', | |
13 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', | |
14 | 'email.body.signature', 'email.subject.prefix', | |
15 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', | |
16 | 'storage.redundancy', 'storage.tmp', 'storage.streaming_playlists', 'storage.plugins', | |
17 | 'log.level', | |
18 | 'user.video_quota', 'user.video_quota_daily', | |
19 | 'csp.enabled', 'csp.report_only', 'csp.report_uri', | |
20 | 'cache.previews.size', 'admin.email', 'contact_form.enabled', | |
21 | 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', | |
22 | 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', | |
23 | 'redundancy.videos.strategies', 'redundancy.videos.check_interval', | |
24 | 'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions', 'transcoding.hls.enabled', | |
25 | 'transcoding.resolutions.0p', 'transcoding.resolutions.240p', 'transcoding.resolutions.360p', 'transcoding.resolutions.480p', | |
26 | 'transcoding.resolutions.720p', 'transcoding.resolutions.1080p', 'transcoding.resolutions.2160p', | |
27 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'auto_blacklist.videos.of_users.enabled', | |
28 | 'trending.videos.interval_days', | |
29 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', | |
30 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', | |
31 | 'services.twitter.username', 'services.twitter.whitelisted', | |
32 | 'followers.instance.enabled', 'followers.instance.manual_approval', | |
33 | 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces', | |
34 | 'history.videos.max_age', 'views.videos.remote.max_age', | |
35 | 'rates_limit.login.window', 'rates_limit.login.max', 'rates_limit.ask_send_email.window', 'rates_limit.ask_send_email.max', | |
36 | 'theme.default', | |
37 | 'remote_redundancy.videos.accept_from', | |
38 | 'federation.videos.federate_unlisted', | |
39 | 'search.remote_uri.users', 'search.remote_uri.anonymous', 'search.search_index.enabled', 'search.search_index.url', | |
40 | 'search.search_index.disable_local_search', 'search.search_index.is_default_search', | |
41 | 'live.enabled', 'live.allow_replay', 'live.max_duration', 'live.max_user_lives', 'live.max_instance_lives', | |
42 | 'live.transcoding.enabled', 'live.transcoding.threads', | |
43 | 'live.transcoding.resolutions.240p', 'live.transcoding.resolutions.360p', 'live.transcoding.resolutions.480p', | |
44 | 'live.transcoding.resolutions.720p', 'live.transcoding.resolutions.1080p', 'live.transcoding.resolutions.2160p' | |
45 | ] | |
46 | ||
47 | const requiredAlternatives = [ | |
48 | [ // set | |
49 | [ 'redis.hostname', 'redis.port' ], // alternative | |
50 | [ 'redis.socket' ] | |
51 | ] | |
52 | ] | |
53 | const miss: string[] = [] | |
54 | ||
55 | for (const key of required) { | |
56 | if (!config.has(key)) { | |
57 | miss.push(key) | |
58 | } | |
59 | } | |
60 | ||
61 | const redundancyVideos = config.get<any>('redundancy.videos.strategies') | |
62 | ||
63 | if (Array.isArray(redundancyVideos)) { | |
64 | for (const r of redundancyVideos) { | |
65 | if (!r.size) miss.push('redundancy.videos.strategies.size') | |
66 | if (!r.min_lifetime) miss.push('redundancy.videos.strategies.min_lifetime') | |
67 | } | |
68 | } | |
69 | ||
70 | const missingAlternatives = requiredAlternatives.filter( | |
71 | set => !set.find(alternative => !alternative.find(key => !config.has(key))) | |
72 | ) | |
73 | ||
74 | missingAlternatives | |
75 | .forEach(set => set[0].forEach(key => miss.push(key))) | |
76 | ||
77 | return miss | |
78 | } | |
79 | ||
80 | // Check the available codecs | |
81 | // We get CONFIG by param to not import it in this file (import orders) | |
82 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { | |
83 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
84 | ||
85 | const Ffmpeg = require('fluent-ffmpeg') | |
86 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) | |
87 | const codecs = await getAvailableCodecsPromise() | |
88 | const canEncode = [ 'libx264' ] | |
89 | ||
90 | for (const codec of canEncode) { | |
91 | if (codecs[codec] === undefined) { | |
92 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
93 | } | |
94 | ||
95 | if (codecs[codec].canEncode !== true) { | |
96 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
97 | } | |
98 | } | |
99 | ||
100 | return checkFFmpegEncoders() | |
101 | } | |
102 | ||
103 | // Detect supported encoders by ffmpeg | |
104 | let supportedEncoders: Map<string, boolean> | |
105 | async function checkFFmpegEncoders (): Promise<Map<string, boolean>> { | |
106 | if (supportedEncoders !== undefined) { | |
107 | return supportedEncoders | |
108 | } | |
109 | ||
110 | const Ffmpeg = require('fluent-ffmpeg') | |
111 | const getAvailableEncodersPromise = promisify0(Ffmpeg.getAvailableEncoders) | |
112 | const availableEncoders = await getAvailableEncodersPromise() | |
113 | ||
114 | const searchEncoders = [ | |
115 | 'aac', | |
116 | 'libfdk_aac', | |
117 | 'libx264' | |
118 | ] | |
119 | ||
120 | supportedEncoders = new Map<string, boolean>() | |
121 | ||
122 | for (const searchEncoder of searchEncoders) { | |
123 | supportedEncoders.set(searchEncoder, availableEncoders[searchEncoder] !== undefined) | |
124 | } | |
125 | ||
126 | return supportedEncoders | |
127 | } | |
128 | ||
129 | function checkNodeVersion () { | |
130 | const v = process.version | |
131 | const majorString = v.split('.')[0].replace('v', '') | |
132 | const major = parseInt(majorString, 10) | |
133 | ||
134 | logger.debug('Checking NodeJS version %s.', v) | |
135 | ||
136 | if (major < 10) { | |
137 | logger.warn('Your NodeJS version %s is deprecated. Please use Node 10.', v) | |
138 | } | |
139 | } | |
140 | ||
141 | // --------------------------------------------------------------------------- | |
142 | ||
143 | export { | |
144 | checkFFmpeg, | |
145 | checkFFmpegEncoders, | |
146 | checkMissedConfig, | |
147 | checkNodeVersion | |
148 | } |