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