diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-14 17:38:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 10:53:16 +0100 |
commit | 50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch) | |
tree | f1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/user.ts | |
parent | fadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff) | |
download | PeerTube-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.ts | 45 |
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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { createPrivateAndPublicKeys, logger } from '../helpers' | 2 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
3 | import { CONFIG, sequelizeTypescript } from '../initializers' | 3 | import { sequelizeTypescript, SERVER_ACTOR_NAME } from '../initializers' |
4 | import { AccountModel } from '../models/account/account' | 4 | import { AccountModel } from '../models/account/account' |
5 | import { UserModel } from '../models/account/user' | 5 | import { UserModel } from '../models/account/user' |
6 | import { ActorModel } from '../models/activitypub/actor' | 6 | import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' |
7 | import { getAccountActivityPubUrl } from './activitypub' | ||
8 | import { createVideoChannel } from './video-channel' | 7 | import { createVideoChannel } from './video-channel' |
9 | 8 | ||
10 | async function createUserAccountAndChannel (user: UserModel, validateUser = true) { | 9 | async 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 | ||
39 | async function createLocalAccountWithoutKeys (name: string, userId: number, applicationId: number, t: Sequelize.Transaction) { | 34 | async 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 | ||
60 | async 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 | ||
72 | export { | 70 | export { |
71 | createApplicationActor, | ||
73 | createUserAccountAndChannel, | 72 | createUserAccountAndChannel, |
74 | createLocalAccountWithoutKeys | 73 | createLocalAccountWithoutKeys |
75 | } | 74 | } |