]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/checker.js
Move the count of results for the pagination in constants module
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.js
index ec7bc0ad2ff14d32d1b55bab385f5a704b01436d..7a2b5b132450eebb2f2d82d4e27a2050bf09310b 100644 (file)
@@ -1,24 +1,25 @@
 'use strict'
 
-var config = require('config')
-var mkdirp = require('mkdirp')
-var path = require('path')
+const config = require('config')
 
-var checker = {
+const Users = require('../models/users')
+
+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 = []
+    'network.friends', 'electron.debug' ]
+  const miss = []
 
-  for (var key of required) {
+  for (const key of required) {
     if (!config.has(key)) {
       miss.push(key)
     }
@@ -27,18 +28,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) {
+  Users.getClients(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) {
+  Users.getUsers(function (err, users) {
+    if (err) return callback(err)
+
+    return callback(null, users.length !== 0)
+  })
 }
 
 // ---------------------------------------------------------------------------