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