]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/checker.js
Server: fix migration at installation
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.js
index ec7bc0ad2ff14d32d1b55bab385f5a704b01436d..2a33009b4ed7b65f26529364b24b0c0d0d5bf415 100644 (file)
@@ -1,24 +1,27 @@
 'use strict'
 
-var config = require('config')
-var mkdirp = require('mkdirp')
-var path = require('path')
+const config = require('config')
+const mongoose = require('mongoose')
 
-var checker = {
+const Client = mongoose.model('OAuthClient')
+const User = mongoose.model('User')
+
+const checker = {
   checkConfig: checkConfig,
-  createDirectoriesIfNotExist: createDirectoriesIfNotExist
+  clientsExist: clientsExist,
+  usersExist: usersExist
 }
 
 // Check the config files
 function checkConfig () {
-  var required = [ 'listen.port',
+  const 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 = []
+    'storage.certs', 'storage.uploads', 'storage.logs', 'storage.thumbnails',
+    'electron.debug' ]
+  const miss = []
 
-  for (var key of required) {
+  for (const key of required) {
     if (!config.has(key)) {
       miss.push(key)
     }
@@ -27,18 +30,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) {
+  Client.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) {
+  User.countTotal(function (err, totalUsers) {
+    if (err) return callback(err)
+
+    return callback(null, totalUsers !== 0)
+  })
 }
 
 // ---------------------------------------------------------------------------