aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/installer.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-11 21:50:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-19 21:22:28 +0100
commitfeb4bdfd9b46e87aadfa7c0d5338cde887d1f58c (patch)
tree2abc9fbc9569760e218fd52835850b757344b420 /server/initializers/installer.js
parent108626609eda75e4ecc0a83a650a4d53c46220e0 (diff)
downloadPeerTube-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.js29
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 @@
3const config = require('config') 3const config = require('config')
4const each = require('async/each') 4const each = require('async/each')
5const mkdirp = require('mkdirp') 5const mkdirp = require('mkdirp')
6const mongoose = require('mongoose')
7const passwordGenerator = require('password-generator') 6const passwordGenerator = require('password-generator')
8const path = require('path') 7const path = require('path')
9const series = require('async/series') 8const series = require('async/series')
10 9
11const checker = require('./checker') 10const checker = require('./checker')
12const constants = require('./constants') 11const constants = require('./constants')
12const db = require('./database')
13const logger = require('../helpers/logger') 13const logger = require('../helpers/logger')
14const peertubeCrypto = require('../helpers/peertube-crypto') 14const peertubeCrypto = require('../helpers/peertube-crypto')
15 15
16const Application = mongoose.model('Application')
17const Client = mongoose.model('OAuthClient')
18const User = mongoose.model('User')
19
20const installer = { 16const installer = {
21 installApplication 17 installApplication
22} 18}
23 19
24function installApplication (callback) { 20function 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}