diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-03-21 21:11:26 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-03-21 21:11:26 +0100 |
commit | 37dc07b292ae4b24011a99146150869bb9c17c65 (patch) | |
tree | 07bd9ade440cc8dd07349a725ba7d38398628d94 /server/initializers/checker.js | |
parent | 9457bf88079a23d28011ff7c65faa56a548b7817 (diff) | |
download | PeerTube-37dc07b292ae4b24011a99146150869bb9c17c65.tar.gz PeerTube-37dc07b292ae4b24011a99146150869bb9c17c65.tar.zst PeerTube-37dc07b292ae4b24011a99146150869bb9c17c65.zip |
Create an "installer" module that create defaults clients/users...
Diffstat (limited to 'server/initializers/checker.js')
-rw-r--r-- | server/initializers/checker.js | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/server/initializers/checker.js b/server/initializers/checker.js index a21e54982..cb62fabf4 100644 --- a/server/initializers/checker.js +++ b/server/initializers/checker.js | |||
@@ -1,12 +1,13 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const config = require('config') | 3 | const config = require('config') |
4 | const mkdirp = require('mkdirp') | 4 | |
5 | const path = require('path') | 5 | const Users = require('../models/users') |
6 | 6 | ||
7 | const checker = { | 7 | const checker = { |
8 | checkConfig: checkConfig, | 8 | checkConfig: checkConfig, |
9 | createDirectoriesIfNotExist: createDirectoriesIfNotExist | 9 | clientsExist: clientsExist, |
10 | usersExist: usersExist | ||
10 | } | 11 | } |
11 | 12 | ||
12 | // Check the config files | 13 | // Check the config files |
@@ -27,18 +28,20 @@ function checkConfig () { | |||
27 | return miss | 28 | return miss |
28 | } | 29 | } |
29 | 30 | ||
30 | // Create directories for the storage if it doesn't exist | 31 | function clientsExist (callback) { |
31 | function createDirectoriesIfNotExist () { | 32 | Users.getClients(function (err, clients) { |
32 | const storages = config.get('storage') | 33 | if (err) return callback(err) |
33 | 34 | ||
34 | for (const key of Object.keys(storages)) { | 35 | return callback(null, clients.length !== 0) |
35 | const dir = storages[key] | 36 | }) |
36 | try { | 37 | } |
37 | mkdirp.sync(path.join(__dirname, '..', '..', dir)) | 38 | |
38 | } catch (error) { | 39 | function usersExist (callback) { |
39 | throw new Error('Cannot create ' + path + ':' + error) | 40 | Users.getUsers(function (err, users) { |
40 | } | 41 | if (err) return callback(err) |
41 | } | 42 | |
43 | return callback(null, users.length !== 0) | ||
44 | }) | ||
42 | } | 45 | } |
43 | 46 | ||
44 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |