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