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