aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/user.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 17:38:41 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:53:16 +0100
commit50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch)
treef1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/user.ts
parentfadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff)
downloadPeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip
Begin moving video channel to actor
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r--server/lib/user.ts45
1 files changed, 22 insertions, 23 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 6aeb198b9..ec1466c6f 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -1,10 +1,9 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { createPrivateAndPublicKeys, logger } from '../helpers' 2import { ActivityPubActorType } from '../../shared/models/activitypub'
3import { CONFIG, sequelizeTypescript } from '../initializers' 3import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../initializers'
4import { AccountModel } from '../models/account/account' 4import { AccountModel } from '../models/account/account'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6import { ActorModel } from '../models/activitypub/actor' 6import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub'
7import { getAccountActivityPubUrl } from './activitypub'
8import { createVideoChannel } from './video-channel' 7import { createVideoChannel } from './video-channel'
9 8
10async function createUserAccountAndChannel (user: UserModel, validateUser = true) { 9async function createUserAccountAndChannel (user: UserModel, validateUser = true) {
@@ -26,31 +25,22 @@ async function createUserAccountAndChannel (user: UserModel, validateUser = true
26 return { account: accountCreated, videoChannel } 25 return { account: accountCreated, videoChannel }
27 }) 26 })
28 27
29 // Set account keys, this could be long so process after the account creation and do not block the client 28 account.Actor = await setAsyncActorKeys(account.Actor)
30 const { publicKey, privateKey } = await createPrivateAndPublicKeys() 29 videoChannel.Actor = await setAsyncActorKeys(videoChannel.Actor)
31 const actor = account.Actor
32 actor.set('publicKey', publicKey)
33 actor.set('privateKey', privateKey)
34 actor.save().catch(err => logger.error('Cannot set public/private keys of actor %d.', actor.uuid, err))
35 30
36 return { account, videoChannel } 31 return { account, videoChannel }
37} 32}
38 33
39async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { 34async function createLocalAccountWithoutKeys (
35 name: string,
36 userId: number,
37 applicationId: number,
38 t: Sequelize.Transaction,
39 type: ActivityPubActorType= 'Person'
40) {
40 const url = getAccountActivityPubUrl(name) 41 const url = getAccountActivityPubUrl(name)
41 42
42 const actorInstance = new ActorModel({ 43 const actorInstance = buildActorInstance(type, url, name)
43 url,
44 publicKey: null,
45 privateKey: null,
46 followersCount: 0,
47 followingCount: 0,
48 inboxUrl: url + '/inbox',
49 outboxUrl: url + '/outbox',
50 sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox',
51 followersUrl: url + '/followers',
52 followingUrl: url + '/following'
53 })
54 const actorInstanceCreated = await actorInstance.save({ transaction: t }) 44 const actorInstanceCreated = await actorInstance.save({ transaction: t })
55 45
56 const accountInstance = new AccountModel({ 46 const accountInstance = new AccountModel({
@@ -67,9 +57,18 @@ async function createLocalAccountWithoutKeys (name: string, userId: number, appl
67 return accountInstanceCreated 57 return accountInstanceCreated
68} 58}
69 59
60async function createApplicationActor (applicationId: number) {
61 const accountCreated = await createLocalAccountWithoutKeys(SERVER_ACTOR_NAME, null, applicationId, undefined, 'Application')
62
63 accountCreated.Actor = await setAsyncActorKeys(accountCreated.Actor)
64
65 return accountCreated
66}
67
70// --------------------------------------------------------------------------- 68// ---------------------------------------------------------------------------
71 69
72export { 70export {
71 createApplicationActor,
73 createUserAccountAndChannel, 72 createUserAccountAndChannel,
74 createLocalAccountWithoutKeys 73 createLocalAccountWithoutKeys
75} 74}