X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Finstaller.ts;h=b0084b368de84e26893c82a143e9d1315e724df1;hb=81e504b34e71e91633442c8021e05f9cd52a49c6;hp=5452743b64865fd399d4fb2601a1b8312765cc1c;hpb=3fd3ab2d34d512b160a5e6084d7609be7b4f4452;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 5452743b6..b0084b368 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -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 = { @@ -119,6 +120,7 @@ async function createOAuthAdminIfNotExist () { email, password, role, + nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, videoQuota: -1 } const user = new UserModel(userData) @@ -133,16 +135,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) }