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