]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker.js
Update migrations code
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b 3const config = require('config')
37dc07b2 4
feb4bdfd 5const db = require('./database')
9f10b292 6
f0f5567b 7const checker = {
c4403b29 8 checkConfig,
b65c27aa 9 checkMissedConfig,
c4403b29
C
10 clientsExist,
11 usersExist
9f10b292
C
12}
13
b65c27aa 14// Some checks on configuration files
9f10b292 15function checkConfig () {
b65c27aa
C
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
27function checkMissedConfig () {
f0f5567b 28 const required = [ 'listen.port',
3737bbaf 29 'webserver.https', 'webserver.hostname', 'webserver.port',
b769007f 30 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
6a94a109 31 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews'
56835348 32 ]
f0f5567b 33 const miss = []
9f10b292 34
f0f5567b 35 for (const key of required) {
9f10b292
C
36 if (!config.has(key)) {
37 miss.push(key)
8c308c2b 38 }
8c308c2b
C
39 }
40
9f10b292
C
41 return miss
42}
43
37dc07b2 44function clientsExist (callback) {
feb4bdfd 45 db.OAuthClient.list(function (err, clients) {
37dc07b2 46 if (err) return callback(err)
9f10b292 47
37dc07b2
C
48 return callback(null, clients.length !== 0)
49 })
50}
51
52function usersExist (callback) {
feb4bdfd 53 db.User.countTotal(function (err, totalUsers) {
37dc07b2
C
54 if (err) return callback(err)
55
089ff2f2 56 return callback(null, totalUsers !== 0)
37dc07b2 57 })
9f10b292 58}
8c308c2b 59
9f10b292 60// ---------------------------------------------------------------------------
c45f7f84 61
9f10b292 62module.exports = checker