diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-12-11 21:50:51 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-12-19 21:22:28 +0100 |
commit | feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c (patch) | |
tree | 2abc9fbc9569760e218fd52835850b757344b420 /server/initializers/installer.js | |
parent | 108626609eda75e4ecc0a83a650a4d53c46220e0 (diff) | |
download | PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.tar.gz PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.tar.zst PeerTube-feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c.zip |
First version with PostgreSQL
Diffstat (limited to 'server/initializers/installer.js')
-rw-r--r-- | server/initializers/installer.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/server/initializers/installer.js b/server/initializers/installer.js index 1df300ba8..4823bc8c8 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.js | |||
@@ -3,26 +3,27 @@ | |||
3 | const config = require('config') | 3 | const config = require('config') |
4 | const each = require('async/each') | 4 | const each = require('async/each') |
5 | const mkdirp = require('mkdirp') | 5 | const mkdirp = require('mkdirp') |
6 | const mongoose = require('mongoose') | ||
7 | const passwordGenerator = require('password-generator') | 6 | const passwordGenerator = require('password-generator') |
8 | const path = require('path') | 7 | const path = require('path') |
9 | const series = require('async/series') | 8 | const series = require('async/series') |
10 | 9 | ||
11 | const checker = require('./checker') | 10 | const checker = require('./checker') |
12 | const constants = require('./constants') | 11 | const constants = require('./constants') |
12 | const db = require('./database') | ||
13 | const logger = require('../helpers/logger') | 13 | const logger = require('../helpers/logger') |
14 | const peertubeCrypto = require('../helpers/peertube-crypto') | 14 | const peertubeCrypto = require('../helpers/peertube-crypto') |
15 | 15 | ||
16 | const Application = mongoose.model('Application') | ||
17 | const Client = mongoose.model('OAuthClient') | ||
18 | const User = mongoose.model('User') | ||
19 | |||
20 | const installer = { | 16 | const installer = { |
21 | installApplication | 17 | installApplication |
22 | } | 18 | } |
23 | 19 | ||
24 | function installApplication (callback) { | 20 | function installApplication (callback) { |
25 | series([ | 21 | series([ |
22 | function createDatabase (callbackAsync) { | ||
23 | db.sequelize.sync().asCallback(callbackAsync) | ||
24 | // db.sequelize.sync({ force: true }).asCallback(callbackAsync) | ||
25 | }, | ||
26 | |||
26 | function createDirectories (callbackAsync) { | 27 | function createDirectories (callbackAsync) { |
27 | createDirectoriesIfNotExist(callbackAsync) | 28 | createDirectoriesIfNotExist(callbackAsync) |
28 | }, | 29 | }, |
@@ -65,16 +66,18 @@ function createOAuthClientIfNotExist (callback) { | |||
65 | 66 | ||
66 | logger.info('Creating a default OAuth Client.') | 67 | logger.info('Creating a default OAuth Client.') |
67 | 68 | ||
68 | const secret = passwordGenerator(32, false) | 69 | const id = passwordGenerator(32, false, /[a-z0-9]/) |
69 | const client = new Client({ | 70 | const secret = passwordGenerator(32, false, /[a-zA-Z0-9]/) |
71 | const client = db.OAuthClient.build({ | ||
72 | clientId: id, | ||
70 | clientSecret: secret, | 73 | clientSecret: secret, |
71 | grants: [ 'password', 'refresh_token' ] | 74 | grants: [ 'password', 'refresh_token' ] |
72 | }) | 75 | }) |
73 | 76 | ||
74 | client.save(function (err, createdClient) { | 77 | client.save().asCallback(function (err, createdClient) { |
75 | if (err) return callback(err) | 78 | if (err) return callback(err) |
76 | 79 | ||
77 | logger.info('Client id: ' + createdClient._id) | 80 | logger.info('Client id: ' + createdClient.clientId) |
78 | logger.info('Client secret: ' + createdClient.clientSecret) | 81 | logger.info('Client secret: ' + createdClient.clientSecret) |
79 | 82 | ||
80 | return callback(null) | 83 | return callback(null) |
@@ -106,21 +109,21 @@ function createOAuthAdminIfNotExist (callback) { | |||
106 | password = passwordGenerator(8, true) | 109 | password = passwordGenerator(8, true) |
107 | } | 110 | } |
108 | 111 | ||
109 | const user = new User({ | 112 | const user = db.User.build({ |
110 | username, | 113 | username, |
111 | password, | 114 | password, |
112 | role | 115 | role |
113 | }) | 116 | }) |
114 | 117 | ||
115 | user.save(function (err, createdUser) { | 118 | user.save().asCallback(function (err, createdUser) { |
116 | if (err) return callback(err) | 119 | if (err) return callback(err) |
117 | 120 | ||
118 | logger.info('Username: ' + username) | 121 | logger.info('Username: ' + username) |
119 | logger.info('User password: ' + password) | 122 | logger.info('User password: ' + password) |
120 | 123 | ||
121 | logger.info('Creating Application collection.') | 124 | logger.info('Creating Application collection.') |
122 | const application = new Application({ mongoSchemaVersion: constants.LAST_MONGO_SCHEMA_VERSION }) | 125 | const application = db.Application.build({ sqlSchemaVersion: constants.LAST_SQL_SCHEMA_VERSION }) |
123 | application.save(callback) | 126 | application.save().asCallback(callback) |
124 | }) | 127 | }) |
125 | }) | 128 | }) |
126 | } | 129 | } |