aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-26 14:22:25 +0100
committerChocobozzz <me@florianbigard.com>2021-02-26 14:22:25 +0100
commit8795d6f254bd8f88c385bf77b82cc6f177c94df9 (patch)
tree88f8f4fced9e0c12db5b43dcac6e44bd94eb8b1a /server/lib
parent92315d979c3f424d81f8fca3c8831d81e4e2a6d6 (diff)
downloadPeerTube-8795d6f254bd8f88c385bf77b82cc6f177c94df9.tar.gz
PeerTube-8795d6f254bd8f88c385bf77b82cc6f177c94df9.tar.zst
PeerTube-8795d6f254bd8f88c385bf77b82cc6f177c94df9.zip
Fix broken local actors
Some channels can't federate because they don't have public/private keys, maybe because the generation failed for various reasons
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/actor.ts20
-rw-r--r--server/lib/job-queue/handlers/actor-keys.ts20
-rw-r--r--server/lib/job-queue/job-queue.ts5
-rw-r--r--server/lib/user.ts8
4 files changed, 37 insertions, 16 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index dbb243d3a..a726f9e20 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -39,17 +39,13 @@ import { getServerActor } from '@server/models/application/application'
39import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 39import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
40 40
41// Set account keys, this could be long so process after the account creation and do not block the client 41// Set account keys, this could be long so process after the account creation and do not block the client
42function setAsyncActorKeys <T extends MActor> (actor: T) { 42async function generateAndSaveActorKeys <T extends MActor> (actor: T) {
43 return createPrivateAndPublicKeys() 43 const { publicKey, privateKey } = await createPrivateAndPublicKeys()
44 .then(({ publicKey, privateKey }) => { 44
45 actor.publicKey = publicKey 45 actor.publicKey = publicKey
46 actor.privateKey = privateKey 46 actor.privateKey = privateKey
47 return actor.save() 47
48 }) 48 return actor.save()
49 .catch(err => {
50 logger.error('Cannot set public/private keys of actor %d.', actor.url, { err })
51 return actor
52 })
53} 49}
54 50
55function getOrCreateActorAndServerAndModel ( 51function getOrCreateActorAndServerAndModel (
@@ -346,7 +342,7 @@ async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannel
346export { 342export {
347 getOrCreateActorAndServerAndModel, 343 getOrCreateActorAndServerAndModel,
348 buildActorInstance, 344 buildActorInstance,
349 setAsyncActorKeys, 345 generateAndSaveActorKeys,
350 fetchActorTotalItems, 346 fetchActorTotalItems,
351 getAvatarInfoIfExists, 347 getAvatarInfoIfExists,
352 updateActorInstance, 348 updateActorInstance,
diff --git a/server/lib/job-queue/handlers/actor-keys.ts b/server/lib/job-queue/handlers/actor-keys.ts
new file mode 100644
index 000000000..8da549640
--- /dev/null
+++ b/server/lib/job-queue/handlers/actor-keys.ts
@@ -0,0 +1,20 @@
1import * as Bull from 'bull'
2import { generateAndSaveActorKeys } from '@server/lib/activitypub/actor'
3import { ActorModel } from '@server/models/activitypub/actor'
4import { ActorKeysPayload } from '@shared/models'
5import { logger } from '../../../helpers/logger'
6
7async function processActorKeys (job: Bull.Job) {
8 const payload = job.data as ActorKeysPayload
9 logger.info('Processing email in job %d.', job.id)
10
11 const actor = await ActorModel.load(payload.actorId)
12
13 await generateAndSaveActorKeys(actor)
14}
15
16// ---------------------------------------------------------------------------
17
18export {
19 processActorKeys
20}
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index 72fed6072..efda2e038 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -7,6 +7,7 @@ import {
7 ActivitypubHttpBroadcastPayload, 7 ActivitypubHttpBroadcastPayload,
8 ActivitypubHttpFetcherPayload, 8 ActivitypubHttpFetcherPayload,
9 ActivitypubHttpUnicastPayload, 9 ActivitypubHttpUnicastPayload,
10 ActorKeysPayload,
10 EmailPayload, 11 EmailPayload,
11 JobState, 12 JobState,
12 JobType, 13 JobType,
@@ -25,6 +26,7 @@ import { processActivityPubHttpBroadcast } from './handlers/activitypub-http-bro
25import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' 26import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'
26import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' 27import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast'
27import { refreshAPObject } from './handlers/activitypub-refresher' 28import { refreshAPObject } from './handlers/activitypub-refresher'
29import { processActorKeys } from './handlers/actor-keys'
28import { processEmail } from './handlers/email' 30import { processEmail } from './handlers/email'
29import { processVideoFileImport } from './handlers/video-file-import' 31import { processVideoFileImport } from './handlers/video-file-import'
30import { processVideoImport } from './handlers/video-import' 32import { processVideoImport } from './handlers/video-import'
@@ -44,6 +46,7 @@ type CreateJobArgument =
44 { type: 'activitypub-refresher', payload: RefreshPayload } | 46 { type: 'activitypub-refresher', payload: RefreshPayload } |
45 { type: 'videos-views', payload: {} } | 47 { type: 'videos-views', payload: {} } |
46 { type: 'video-live-ending', payload: VideoLiveEndingPayload } | 48 { type: 'video-live-ending', payload: VideoLiveEndingPayload } |
49 { type: 'actor-keys', payload: ActorKeysPayload } |
47 { type: 'video-redundancy', payload: VideoRedundancyPayload } 50 { type: 'video-redundancy', payload: VideoRedundancyPayload }
48 51
49type CreateJobOptions = { 52type CreateJobOptions = {
@@ -63,6 +66,7 @@ const handlers: { [id in JobType]: (job: Bull.Job) => Promise<any> } = {
63 'videos-views': processVideosViews, 66 'videos-views': processVideosViews,
64 'activitypub-refresher': refreshAPObject, 67 'activitypub-refresher': refreshAPObject,
65 'video-live-ending': processVideoLiveEnding, 68 'video-live-ending': processVideoLiveEnding,
69 'actor-keys': processActorKeys,
66 'video-redundancy': processVideoRedundancy 70 'video-redundancy': processVideoRedundancy
67} 71}
68 72
@@ -78,6 +82,7 @@ const jobTypes: JobType[] = [
78 'videos-views', 82 'videos-views',
79 'activitypub-refresher', 83 'activitypub-refresher',
80 'video-redundancy', 84 'video-redundancy',
85 'actor-keys',
81 'video-live-ending' 86 'video-live-ending'
82] 87]
83 88
diff --git a/server/lib/user.ts b/server/lib/user.ts
index 6b0fd9b88..e1892f22c 100644
--- a/server/lib/user.ts
+++ b/server/lib/user.ts
@@ -10,7 +10,7 @@ import { UserNotificationSettingModel } from '../models/account/user-notificatio
10import { ActorModel } from '../models/activitypub/actor' 10import { ActorModel } from '../models/activitypub/actor'
11import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models' 11import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models'
12import { MUser, MUserDefault, MUserId } from '../types/models/user' 12import { MUser, MUserDefault, MUserId } from '../types/models/user'
13import { buildActorInstance, setAsyncActorKeys } from './activitypub/actor' 13import { buildActorInstance, generateAndSaveActorKeys } from './activitypub/actor'
14import { getLocalAccountActivityPubUrl } from './activitypub/url' 14import { getLocalAccountActivityPubUrl } from './activitypub/url'
15import { Emailer } from './emailer' 15import { Emailer } from './emailer'
16import { LiveManager } from './live-manager' 16import { LiveManager } from './live-manager'
@@ -55,8 +55,8 @@ async function createUserAccountAndChannelAndPlaylist (parameters: {
55 }) 55 })
56 56
57 const [ accountActorWithKeys, channelActorWithKeys ] = await Promise.all([ 57 const [ accountActorWithKeys, channelActorWithKeys ] = await Promise.all([
58 setAsyncActorKeys(account.Actor), 58 generateAndSaveActorKeys(account.Actor),
59 setAsyncActorKeys(videoChannel.Actor) 59 generateAndSaveActorKeys(videoChannel.Actor)
60 ]) 60 ])
61 61
62 account.Actor = accountActorWithKeys 62 account.Actor = accountActorWithKeys
@@ -101,7 +101,7 @@ async function createApplicationActor (applicationId: number) {
101 type: 'Application' 101 type: 'Application'
102 }) 102 })
103 103
104 accountCreated.Actor = await setAsyncActorKeys(accountCreated.Actor) 104 accountCreated.Actor = await generateAndSaveActorKeys(accountCreated.Actor)
105 105
106 return accountCreated 106 return accountCreated
107} 107}