]>
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 = { |
9f10b292 | 10 | checkConfig: checkConfig, |
37dc07b2 C |
11 | clientsExist: clientsExist, |
12 | usersExist: usersExist | |
9f10b292 C |
13 | } |
14 | ||
15 | // Check the config files | |
16 | function checkConfig () { | |
f0f5567b | 17 | const required = [ 'listen.port', |
9f10b292 C |
18 | 'webserver.https', 'webserver.host', 'webserver.port', |
19 | 'database.host', 'database.port', 'database.suffix', | |
20 | 'storage.certs', 'storage.uploads', 'storage.logs', | |
09bc69df | 21 | 'network.friends', 'electron.debug' ] |
f0f5567b | 22 | const miss = [] |
9f10b292 | 23 | |
f0f5567b | 24 | for (const key of required) { |
9f10b292 C |
25 | if (!config.has(key)) { |
26 | miss.push(key) | |
8c308c2b | 27 | } |
8c308c2b C |
28 | } |
29 | ||
9f10b292 C |
30 | return miss |
31 | } | |
32 | ||
37dc07b2 | 33 | function clientsExist (callback) { |
69b0a27c | 34 | Client.list(function (err, clients) { |
37dc07b2 | 35 | if (err) return callback(err) |
9f10b292 | 36 | |
37dc07b2 C |
37 | return callback(null, clients.length !== 0) |
38 | }) | |
39 | } | |
40 | ||
41 | function usersExist (callback) { | |
69b0a27c | 42 | User.list(function (err, users) { |
37dc07b2 C |
43 | if (err) return callback(err) |
44 | ||
45 | return callback(null, users.length !== 0) | |
46 | }) | |
9f10b292 | 47 | } |
8c308c2b | 48 | |
9f10b292 | 49 | // --------------------------------------------------------------------------- |
c45f7f84 | 50 | |
9f10b292 | 51 | module.exports = checker |