X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fuser.ts;h=2d7b36b4faae0e6dc380267ff78664db991df5c0;hb=47e0652b4a98916d4a1d012fbec61afd73a30565;hp=9884e566f9f5ea0a69bd0db44dd0eb8f5322f125;hpb=41dbdb8acff3ac56187e8149eab0ff82e2377597;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/user.ts b/server/lib/user.ts index 9884e566f..2d7b36b4f 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -5,16 +5,17 @@ import { database as db } from '../initializers' import { CONFIG } from '../initializers/constants' import { UserInstance } from '../models' import { createVideoChannel } from './video-channel' +import { logger } from '../helpers/logger' async function createUserAccountAndChannel (user: UserInstance, validateUser = true) { - const res = await db.sequelize.transaction(async t => { + const { account, videoChannel } = await db.sequelize.transaction(async t => { const userOptions = { transaction: t, validate: validateUser } const userCreated = await user.save(userOptions) - const accountCreated = await createLocalAccount(user.username, user.id, null, t) + const accountCreated = await createLocalAccountWithoutKeys(user.username, user.id, null, t) const videoChannelName = `Default ${userCreated.username} channel` const videoChannelInfo = { @@ -25,18 +26,23 @@ async function createUserAccountAndChannel (user: UserInstance, validateUser = t return { account: accountCreated, videoChannel } }) - return res + // Set account keys, this could be long so process after the account creation and do not block the client + const { publicKey, privateKey } = await createPrivateAndPublicKeys() + account.set('publicKey', publicKey) + account.set('privateKey', privateKey) + account.save().catch(err => logger.error('Cannot set public/private keys of local account %d.', account.id, err)) + + return { account, videoChannel } } -async function createLocalAccount (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { - const { publicKey, privateKey } = await createPrivateAndPublicKeys() +async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { const url = getActivityPubUrl('account', name) const accountInstance = db.Account.build({ name, url, - publicKey, - privateKey, + publicKey: null, + privateKey: null, followersCount: 0, followingCount: 0, inboxUrl: url + '/inbox', @@ -56,5 +62,5 @@ async function createLocalAccount (name: string, userId: number, applicationId: export { createUserAccountAndChannel, - createLocalAccount + createLocalAccountWithoutKeys }