]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as config from 'config' |
9f10b292 | 2 | |
e02643f3 | 3 | import { database as db } from './database' |
65fcc311 | 4 | import { CONFIG } from './constants' |
6fcd19ba | 5 | import { promisify0 } from '../helpers/core-utils' |
9f10b292 | 6 | |
b65c27aa | 7 | // Some checks on configuration files |
9f10b292 | 8 | function checkConfig () { |
b65c27aa C |
9 | if (config.has('webserver.host')) { |
10 | let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!' | |
11 | errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.' | |
12 | ||
13 | return errorMessage | |
14 | } | |
15 | ||
16 | return null | |
17 | } | |
18 | ||
19 | // Check the config files | |
20 | function checkMissedConfig () { | |
f0f5567b | 21 | const required = [ 'listen.port', |
3737bbaf | 22 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
b769007f | 23 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
4793c343 | 24 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', |
227d02fe | 25 | 'admin.email', 'signup.enabled', 'transcoding.enabled', 'transcoding.threads' |
56835348 | 26 | ] |
69818c93 | 27 | const miss: string[] = [] |
9f10b292 | 28 | |
f0f5567b | 29 | for (const key of required) { |
9f10b292 C |
30 | if (!config.has(key)) { |
31 | miss.push(key) | |
8c308c2b | 32 | } |
8c308c2b C |
33 | } |
34 | ||
9f10b292 C |
35 | return miss |
36 | } | |
37 | ||
e5b88539 | 38 | // Check the available codecs |
6fcd19ba | 39 | function checkFFmpeg () { |
e5b88539 | 40 | const Ffmpeg = require('fluent-ffmpeg') |
6fcd19ba C |
41 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
42 | ||
43 | getAvailableCodecsPromise() | |
44 | .then(codecs => { | |
45 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
46 | ||
47 | const canEncode = [ 'libx264' ] | |
075f16ca | 48 | canEncode.forEach(codec => { |
6fcd19ba C |
49 | if (codecs[codec] === undefined) { |
50 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
51 | } | |
52 | ||
53 | if (codecs[codec].canEncode !== true) { | |
54 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
55 | } | |
56 | }) | |
e5b88539 | 57 | }) |
e5b88539 C |
58 | } |
59 | ||
6fcd19ba C |
60 | function clientsExist () { |
61 | return db.OAuthClient.countTotal().then(totalClients => { | |
62 | return totalClients !== 0 | |
37dc07b2 C |
63 | }) |
64 | } | |
65 | ||
6fcd19ba C |
66 | function usersExist () { |
67 | return db.User.countTotal().then(totalUsers => { | |
68 | return totalUsers !== 0 | |
37dc07b2 | 69 | }) |
9f10b292 | 70 | } |
8c308c2b | 71 | |
9f10b292 | 72 | // --------------------------------------------------------------------------- |
c45f7f84 | 73 | |
65fcc311 C |
74 | export { |
75 | checkConfig, | |
76 | checkFFmpeg, | |
77 | checkMissedConfig, | |
78 | clientsExist, | |
79 | usersExist | |
80 | } |