]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/installer.ts
Upgrade changelog
[github/Chocobozzz/PeerTube.git] / server / initializers / installer.ts
index 5452743b64865fd399d4fb2601a1b8312765cc1c..09c6d54735b14dd29f3d95293fbb573501b4c41f 100644 (file)
@@ -1,12 +1,13 @@
 import * as passwordGenerator from 'password-generator'
 import { UserRole } from '../../shared'
-import { createPrivateAndPublicKeys, logger, mkdirpPromise, rimrafPromise } from '../helpers'
-import { createLocalAccountWithoutKeys, createUserAccountAndChannel } from '../lib'
+import { mkdirpPromise, rimrafPromise } from '../helpers/core-utils'
+import { logger } from '../helpers/logger'
+import { createApplicationActor, createUserAccountAndChannel } from '../lib/user'
 import { UserModel } from '../models/account/user'
 import { ApplicationModel } from '../models/application/application'
 import { OAuthClientModel } from '../models/oauth/oauth-client'
 import { applicationExist, clientsExist, usersExist } from './checker'
-import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants'
+import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants'
 import { sequelizeTypescript } from './database'
 
 async function installApplication () {
@@ -18,8 +19,8 @@ async function installApplication () {
     await createOAuthClientIfNotExist()
     await createOAuthAdminIfNotExist()
   } catch (err) {
-    logger.error('Cannot install application.', err)
-    throw err
+    logger.error('Cannot install application.', { err })
+    process.exit(-1)
   }
 }
 
@@ -111,7 +112,7 @@ async function createOAuthAdminIfNotExist () {
     // Our password is weak so do not validate it
     validatePassword = false
   } else {
-    password = passwordGenerator(8, true)
+    password = passwordGenerator(16, true)
   }
 
   const userData = {
@@ -133,16 +134,11 @@ async function createApplicationIfNotExist () {
   // Nothing to do, application already exist
   if (exist === true) return undefined
 
-  logger.info('Creating Application table.')
-  const applicationInstance = await ApplicationModel.create({ migrationVersion: LAST_MIGRATION_VERSION })
-
   logger.info('Creating application account.')
 
-  const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined)
-
-  const { publicKey, privateKey } = await createPrivateAndPublicKeys()
-  accountCreated.set('publicKey', publicKey)
-  accountCreated.set('privateKey', privateKey)
+  const application = await ApplicationModel.create({
+    migrationVersion: LAST_MIGRATION_VERSION
+  })
 
-  return accountCreated.save()
+  return createApplicationActor(application.id)
 }