]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b | 3 | const config = require('config') |
69b0a27c | 4 | const mongoose = require('mongoose') |
37dc07b2 | 5 | |
69b0a27c C |
6 | const Client = mongoose.model('OAuthClient') |
7 | const User = mongoose.model('User') | |
9f10b292 | 8 | |
f0f5567b | 9 | const checker = { |
c4403b29 | 10 | checkConfig, |
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 C |
31 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
32 | 'database.hostname', 'database.port', 'database.suffix', | |
6a94a109 | 33 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews' |
56835348 | 34 | ] |
f0f5567b | 35 | const miss = [] |
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 | ||
9f10b292 C |
43 | return miss |
44 | } | |
45 | ||
37dc07b2 | 46 | function clientsExist (callback) { |
69b0a27c | 47 | Client.list(function (err, clients) { |
37dc07b2 | 48 | if (err) return callback(err) |
9f10b292 | 49 | |
37dc07b2 C |
50 | return callback(null, clients.length !== 0) |
51 | }) | |
52 | } | |
53 | ||
54 | function usersExist (callback) { | |
5c39adb7 | 55 | User.countTotal(function (err, totalUsers) { |
37dc07b2 C |
56 | if (err) return callback(err) |
57 | ||
089ff2f2 | 58 | return callback(null, totalUsers !== 0) |
37dc07b2 | 59 | }) |
9f10b292 | 60 | } |
8c308c2b | 61 | |
9f10b292 | 62 | // --------------------------------------------------------------------------- |
c45f7f84 | 63 | |
9f10b292 | 64 | module.exports = checker |