]>
Commit | Line | Data |
---|---|---|
1 | 'use strict' | |
2 | ||
3 | const config = require('config') | |
4 | const mongoose = require('mongoose') | |
5 | ||
6 | const Client = mongoose.model('OAuthClient') | |
7 | const User = mongoose.model('User') | |
8 | ||
9 | const checker = { | |
10 | checkConfig, | |
11 | checkMissedConfig, | |
12 | clientsExist, | |
13 | usersExist | |
14 | } | |
15 | ||
16 | // Some checks on configuration files | |
17 | function checkConfig () { | |
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 () { | |
30 | const required = [ 'listen.port', | |
31 | 'webserver.https', 'webserver.hostname', 'webserver.port', | |
32 | 'database.hostname', 'database.port', 'database.suffix', | |
33 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews' | |
34 | ] | |
35 | const miss = [] | |
36 | ||
37 | for (const key of required) { | |
38 | if (!config.has(key)) { | |
39 | miss.push(key) | |
40 | } | |
41 | } | |
42 | ||
43 | return miss | |
44 | } | |
45 | ||
46 | function clientsExist (callback) { | |
47 | Client.list(function (err, clients) { | |
48 | if (err) return callback(err) | |
49 | ||
50 | return callback(null, clients.length !== 0) | |
51 | }) | |
52 | } | |
53 | ||
54 | function usersExist (callback) { | |
55 | User.countTotal(function (err, totalUsers) { | |
56 | if (err) return callback(err) | |
57 | ||
58 | return callback(null, totalUsers !== 0) | |
59 | }) | |
60 | } | |
61 | ||
62 | // --------------------------------------------------------------------------- | |
63 | ||
64 | module.exports = checker |