X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=server%2Finitializers%2Finstaller.ts;h=9545160571457f63decf73fb9d55ec3f316407f9;hb=c60774b05b12d262ed27d8efeb0905ac283eeebb;hp=5221b81a5bc3de95042f848f1b8403b4f5c215a6;hpb=e34c85e527100c0b5c44567bd951e95be41b8d7e;p=oweals%2Fpeertube.git diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 5221b81a5..954516057 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts @@ -2,20 +2,20 @@ import * as passwordGenerator from 'password-generator' import { UserRole } from '../../shared' import { logger, mkdirpPromise, rimrafPromise } from '../helpers' import { createUserAccountAndChannel } from '../lib' -import { createLocalAccount } from '../lib/user' -import { clientsExist, usersExist } from './checker' -import { CACHE, CONFIG, LAST_MIGRATION_VERSION } from './constants' - +import { createLocalAccountWithoutKeys } from '../lib/user' +import { applicationExist, clientsExist, usersExist } from './checker' +import { CACHE, CONFIG, LAST_MIGRATION_VERSION, SERVER_ACCOUNT_NAME } from './constants' import { database as db } from './database' +import { createPrivateAndPublicKeys } from '../helpers/peertube-crypto' async function installApplication () { try { await db.sequelize.sync() await removeCacheDirectories() await createDirectoriesIfNotExist() + await createApplicationIfNotExist() await createOAuthClientIfNotExist() await createOAuthAdminIfNotExist() - await createApplicationIfNotExist() } catch (err) { logger.error('Cannot install application.', err) throw err @@ -128,9 +128,20 @@ async function createOAuthAdminIfNotExist () { } async function createApplicationIfNotExist () { + const exist = await applicationExist(db.Application) + // Nothing to do, application already exist + if (exist === true) return undefined + logger.info('Creating Application table.') const applicationInstance = await db.Application.create({ migrationVersion: LAST_MIGRATION_VERSION }) logger.info('Creating application account.') - return createLocalAccount('peertube', null, applicationInstance.id, undefined) + + const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACCOUNT_NAME, null, applicationInstance.id, undefined) + + const { publicKey, privateKey } = await createPrivateAndPublicKeys() + accountCreated.set('publicKey', publicKey) + accountCreated.set('privateKey', privateKey) + + return accountCreated.save() }