]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker-before-init.ts
Implement contact form in the client
[github/Chocobozzz/PeerTube.git] / server / initializers / checker-before-init.ts
CommitLineData
4d4e5cd4 1import * as config from 'config'
e5565833 2import { promisify0 } from '../helpers/core-utils'
c48e82b5 3import { 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
8function 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',
6040f87d 15 'storage.redundancy', 'storage.tmp',
a465bf5f 16 'log.level',
bee0abff 17 'user.video_quota', 'user.video_quota_daily',
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',
9a629c6e 23 'import.videos.http.enabled', 'import.videos.torrent.enabled',
df39a683 24 'trending.videos.interval_days',
0883b324 25 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
5447516b 26 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt',
8be1afa1 27 'services.twitter.username', 'services.twitter.whitelisted'
56835348 28 ]
19f7b248
RK
29 const requiredAlternatives = [
30 [ // set
31 ['redis.hostname', 'redis.port'], // alternative
32 ['redis.socket']
33 ]
34 ]
69818c93 35 const miss: string[] = []
9f10b292 36
f0f5567b 37 for (const key of required) {
9f10b292
C
38 if (!config.has(key)) {
39 miss.push(key)
8c308c2b 40 }
8c308c2b
C
41 }
42
e5565833
C
43 const redundancyVideos = config.get<any>('redundancy.videos.strategies')
44 if (isArray(redundancyVideos)) {
45 for (const r of redundancyVideos) {
46 if (!r.size) miss.push('redundancy.videos.strategies.size')
47 if (!r.min_lifetime) miss.push('redundancy.videos.strategies.min_lifetime')
48 }
49 }
50
19f7b248
RK
51 const missingAlternatives = requiredAlternatives.filter(
52 set => !set.find(alternative => !alternative.find(key => !config.has(key)))
53 )
54
55 missingAlternatives
56 .forEach(set => set[0].forEach(key => miss.push(key)))
57
9f10b292
C
58 return miss
59}
60
e5b88539 61// Check the available codecs
3482688c 62// We get CONFIG by param to not import it in this file (import orders)
f5028693 63async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
e5b88539 64 const Ffmpeg = require('fluent-ffmpeg')
6fcd19ba 65 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
f5028693 66 const codecs = await getAvailableCodecsPromise()
4176e227
RK
67 const canEncode = [ 'libx264' ]
68
f5028693
C
69 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
70
f5028693
C
71 for (const codec of canEncode) {
72 if (codecs[codec] === undefined) {
73 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
74 }
75
76 if (codecs[codec].canEncode !== true) {
77 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
78 }
79 }
4176e227 80
cdf4cb9e 81 return checkFFmpegEncoders()
4176e227
RK
82}
83
84// Optional encoders, if present, can be used to improve transcoding
85// Here we ask ffmpeg if it detects their presence on the system, so that we can later use them
86let supportedOptionalEncoders: Map<string, boolean>
87async function checkFFmpegEncoders (): Promise<Map<string, boolean>> {
88 if (supportedOptionalEncoders !== undefined) {
89 return supportedOptionalEncoders
90 }
91
92 const Ffmpeg = require('fluent-ffmpeg')
93 const getAvailableEncodersPromise = promisify0(Ffmpeg.getAvailableEncoders)
94 const encoders = await getAvailableEncodersPromise()
95 const optionalEncoders = [ 'libfdk_aac' ]
96 supportedOptionalEncoders = new Map<string, boolean>()
97
98 for (const encoder of optionalEncoders) {
cdf4cb9e 99 supportedOptionalEncoders.set(encoder, encoders[encoder] !== undefined)
4176e227 100 }
cdf4cb9e
C
101
102 return supportedOptionalEncoders
e5b88539
C
103}
104
9f10b292 105// ---------------------------------------------------------------------------
c45f7f84 106
65fcc311 107export {
65fcc311 108 checkFFmpeg,
4176e227 109 checkFFmpegEncoders,
e5565833 110 checkMissedConfig
65fcc311 111}