]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b | 3 | const config = require('config') |
37dc07b2 | 4 | |
feb4bdfd | 5 | const db = require('./database') |
9f10b292 | 6 | |
f0f5567b | 7 | const checker = { |
c4403b29 | 8 | checkConfig, |
b65c27aa | 9 | checkMissedConfig, |
c4403b29 C |
10 | clientsExist, |
11 | usersExist | |
9f10b292 C |
12 | } |
13 | ||
b65c27aa | 14 | // Some checks on configuration files |
9f10b292 | 15 | function checkConfig () { |
b65c27aa C |
16 | if (config.has('webserver.host')) { |
17 | let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!' | |
18 | errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.' | |
19 | ||
20 | return errorMessage | |
21 | } | |
22 | ||
23 | return null | |
24 | } | |
25 | ||
26 | // Check the config files | |
27 | function checkMissedConfig () { | |
f0f5567b | 28 | const required = [ 'listen.port', |
3737bbaf | 29 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
b769007f | 30 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
4793c343 C |
31 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', |
32 | 'admin.email' | |
56835348 | 33 | ] |
f0f5567b | 34 | const miss = [] |
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 | ||
9f10b292 C |
42 | return miss |
43 | } | |
44 | ||
37dc07b2 | 45 | function clientsExist (callback) { |
4712081f | 46 | db.OAuthClient.countTotal(function (err, totalClients) { |
37dc07b2 | 47 | if (err) return callback(err) |
9f10b292 | 48 | |
4712081f | 49 | return callback(null, totalClients !== 0) |
37dc07b2 C |
50 | }) |
51 | } | |
52 | ||
53 | function usersExist (callback) { | |
feb4bdfd | 54 | db.User.countTotal(function (err, totalUsers) { |
37dc07b2 C |
55 | if (err) return callback(err) |
56 | ||
089ff2f2 | 57 | return callback(null, totalUsers !== 0) |
37dc07b2 | 58 | }) |
9f10b292 | 59 | } |
8c308c2b | 60 | |
9f10b292 | 61 | // --------------------------------------------------------------------------- |
c45f7f84 | 62 | |
9f10b292 | 63 | module.exports = checker |