]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker.js
Use const/let now we use node 4.2
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b
C
3const config = require('config')
4const mkdirp = require('mkdirp')
5const path = require('path')
9f10b292 6
f0f5567b 7const checker = {
9f10b292
C
8 checkConfig: checkConfig,
9 createDirectoriesIfNotExist: createDirectoriesIfNotExist
10}
11
12// Check the config files
13function checkConfig () {
f0f5567b 14 const required = [ 'listen.port',
9f10b292
C
15 'webserver.https', 'webserver.host', 'webserver.port',
16 'database.host', 'database.port', 'database.suffix',
17 'storage.certs', 'storage.uploads', 'storage.logs',
18 'network.friends' ]
f0f5567b 19 const miss = []
9f10b292 20
f0f5567b 21 for (const key of required) {
9f10b292
C
22 if (!config.has(key)) {
23 miss.push(key)
8c308c2b 24 }
8c308c2b
C
25 }
26
9f10b292
C
27 return miss
28}
29
30// Create directories for the storage if it doesn't exist
31function createDirectoriesIfNotExist () {
f0f5567b 32 const storages = config.get('storage')
9f10b292 33
f0f5567b
C
34 for (const key of Object.keys(storages)) {
35 const dir = storages[key]
9f10b292 36 try {
3d446a26 37 mkdirp.sync(path.join(__dirname, '..', '..', dir))
9f10b292 38 } catch (error) {
ac2f99eb 39 throw new Error('Cannot create ' + path + ':' + error)
8c308c2b
C
40 }
41 }
9f10b292 42}
8c308c2b 43
9f10b292 44// ---------------------------------------------------------------------------
c45f7f84 45
9f10b292 46module.exports = checker