]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/checker.js
Update migrations code
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.js
index ec7bc0ad2ff14d32d1b55bab385f5a704b01436d..2753604dc43bb6eb492a177b666cd20a8a2b982c 100644 (file)
@@ -1,24 +1,38 @@
 'use strict'
 
-var config = require('config')
-var mkdirp = require('mkdirp')
-var path = require('path')
+const config = require('config')
 
-var checker = {
-  checkConfig: checkConfig,
-  createDirectoriesIfNotExist: createDirectoriesIfNotExist
+const db = require('./database')
+
+const checker = {
+  checkConfig,
+  checkMissedConfig,
+  clientsExist,
+  usersExist
 }
 
-// Check the config files
+// Some checks on configuration files
 function checkConfig () {
-  var required = [ 'listen.port',
-    'webserver.https', 'webserver.host', 'webserver.port',
-    'database.host', 'database.port', 'database.suffix',
-    'storage.certs', 'storage.uploads', 'storage.logs',
-    'network.friends' ]
-  var miss = []
-
-  for (var key of required) {
+  if (config.has('webserver.host')) {
+    let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!'
+    errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.'
+
+    return errorMessage
+  }
+
+  return null
+}
+
+// Check the config files
+function checkMissedConfig () {
+  const required = [ 'listen.port',
+    'webserver.https', 'webserver.hostname', 'webserver.port',
+    'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
+    'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews'
+  ]
+  const miss = []
+
+  for (const key of required) {
     if (!config.has(key)) {
       miss.push(key)
     }
@@ -27,18 +41,20 @@ function checkConfig () {
   return miss
 }
 
-// Create directories for the storage if it doesn't exist
-function createDirectoriesIfNotExist () {
-  var storages = config.get('storage')
+function clientsExist (callback) {
+  db.OAuthClient.list(function (err, clients) {
+    if (err) return callback(err)
 
-  for (var key of Object.keys(storages)) {
-    var dir = storages[key]
-    try {
-      mkdirp.sync(path.join(__dirname, '..', dir))
-    } catch (error) {
-      throw new Error('Cannot create ' + path + ':' + error)
-    }
-  }
+    return callback(null, clients.length !== 0)
+  })
+}
+
+function usersExist (callback) {
+  db.User.countTotal(function (err, totalUsers) {
+    if (err) return callback(err)
+
+    return callback(null, totalUsers !== 0)
+  })
 }
 
 // ---------------------------------------------------------------------------