]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as config from 'config' |
e5565833 | 2 | import { promisify0 } from '../helpers/core-utils' |
9f10b292 | 3 | |
e5565833 | 4 | // ONLY USE CORE MODULES IN THIS FILE! |
b65c27aa C |
5 | |
6 | // Check the config files | |
7 | function checkMissedConfig () { | |
cff8b272 | 8 | const required = [ 'listen.port', 'listen.hostname', |
3737bbaf | 9 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
490b595a | 10 | 'trust_proxy', |
1c3386e8 | 11 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', 'database.pool.max', |
a465bf5f C |
12 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', |
13 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', | |
9c6ca37f | 14 | 'storage.redundancy', 'storage.tmp', 'storage.streaming_playlists', |
a465bf5f | 15 | 'log.level', |
bee0abff | 16 | 'user.video_quota', 'user.video_quota_daily', |
539d3f4f | 17 | 'csp.enabled', 'csp.report_only', 'csp.report_uri', |
d3e56c0c | 18 | 'cache.previews.size', 'admin.email', 'contact_form.enabled', |
d9eaee39 JM |
19 | 'signup.enabled', 'signup.limit', 'signup.requires_email_verification', |
20 | 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', | |
f9f899b9 | 21 | 'redundancy.videos.strategies', 'redundancy.videos.check_interval', |
14e2014a | 22 | 'transcoding.enabled', 'transcoding.threads', 'transcoding.allow_additional_extensions', |
7ccddd7b | 23 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'auto_blacklist.videos.of_users.enabled', |
df39a683 | 24 | 'trending.videos.interval_days', |
0883b324 | 25 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', |
f8802489 | 26 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', |
5b9c965d | 27 | 'services.twitter.username', 'services.twitter.whitelisted', |
31b6ddf8 | 28 | 'followers.instance.enabled', 'followers.instance.manual_approval', |
cda03765 | 29 | 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces', |
c342726a YB |
30 | 'history.videos.max_age', 'views.videos.remote.max_age', |
31 | 'rates_limit.login.window', 'rates_limit.login.max', 'rates_limit.ask_send_email.window', 'rates_limit.ask_send_email.max' | |
56835348 | 32 | ] |
19f7b248 RK |
33 | const requiredAlternatives = [ |
34 | [ // set | |
35 | ['redis.hostname', 'redis.port'], // alternative | |
36 | ['redis.socket'] | |
37 | ] | |
38 | ] | |
69818c93 | 39 | const miss: string[] = [] |
9f10b292 | 40 | |
f0f5567b | 41 | for (const key of required) { |
9f10b292 C |
42 | if (!config.has(key)) { |
43 | miss.push(key) | |
8c308c2b | 44 | } |
8c308c2b C |
45 | } |
46 | ||
e5565833 | 47 | const redundancyVideos = config.get<any>('redundancy.videos.strategies') |
d85798c4 C |
48 | |
49 | if (Array.isArray(redundancyVideos)) { | |
e5565833 C |
50 | for (const r of redundancyVideos) { |
51 | if (!r.size) miss.push('redundancy.videos.strategies.size') | |
52 | if (!r.min_lifetime) miss.push('redundancy.videos.strategies.min_lifetime') | |
53 | } | |
54 | } | |
55 | ||
19f7b248 RK |
56 | const missingAlternatives = requiredAlternatives.filter( |
57 | set => !set.find(alternative => !alternative.find(key => !config.has(key))) | |
58 | ) | |
59 | ||
60 | missingAlternatives | |
61 | .forEach(set => set[0].forEach(key => miss.push(key))) | |
62 | ||
9f10b292 C |
63 | return miss |
64 | } | |
65 | ||
e5b88539 | 66 | // Check the available codecs |
3482688c | 67 | // We get CONFIG by param to not import it in this file (import orders) |
f5028693 | 68 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { |
e5b88539 | 69 | const Ffmpeg = require('fluent-ffmpeg') |
6fcd19ba | 70 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
f5028693 | 71 | const codecs = await getAvailableCodecsPromise() |
4176e227 RK |
72 | const canEncode = [ 'libx264' ] |
73 | ||
f5028693 C |
74 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined |
75 | ||
f5028693 C |
76 | for (const codec of canEncode) { |
77 | if (codecs[codec] === undefined) { | |
78 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
79 | } | |
80 | ||
81 | if (codecs[codec].canEncode !== true) { | |
82 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
83 | } | |
84 | } | |
4176e227 | 85 | |
cdf4cb9e | 86 | return checkFFmpegEncoders() |
4176e227 RK |
87 | } |
88 | ||
89 | // Optional encoders, if present, can be used to improve transcoding | |
90 | // Here we ask ffmpeg if it detects their presence on the system, so that we can later use them | |
91 | let supportedOptionalEncoders: Map<string, boolean> | |
92 | async function checkFFmpegEncoders (): Promise<Map<string, boolean>> { | |
93 | if (supportedOptionalEncoders !== undefined) { | |
94 | return supportedOptionalEncoders | |
95 | } | |
96 | ||
97 | const Ffmpeg = require('fluent-ffmpeg') | |
98 | const getAvailableEncodersPromise = promisify0(Ffmpeg.getAvailableEncoders) | |
99 | const encoders = await getAvailableEncodersPromise() | |
100 | const optionalEncoders = [ 'libfdk_aac' ] | |
101 | supportedOptionalEncoders = new Map<string, boolean>() | |
102 | ||
103 | for (const encoder of optionalEncoders) { | |
cdf4cb9e | 104 | supportedOptionalEncoders.set(encoder, encoders[encoder] !== undefined) |
4176e227 | 105 | } |
cdf4cb9e C |
106 | |
107 | return supportedOptionalEncoders | |
e5b88539 C |
108 | } |
109 | ||
9f10b292 | 110 | // --------------------------------------------------------------------------- |
c45f7f84 | 111 | |
65fcc311 | 112 | export { |
65fcc311 | 113 | checkFFmpeg, |
4176e227 | 114 | checkFFmpegEncoders, |
e5565833 | 115 | checkMissedConfig |
65fcc311 | 116 | } |