diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-26 14:22:25 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-26 14:22:25 +0100 |
commit | 8795d6f254bd8f88c385bf77b82cc6f177c94df9 (patch) | |
tree | 88f8f4fced9e0c12db5b43dcac6e44bd94eb8b1a /server/lib | |
parent | 92315d979c3f424d81f8fca3c8831d81e4e2a6d6 (diff) | |
download | PeerTube-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.ts | 20 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/actor-keys.ts | 20 | ||||
-rw-r--r-- | server/lib/job-queue/job-queue.ts | 5 | ||||
-rw-r--r-- | server/lib/user.ts | 8 |
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' | |||
39 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 39 | import { 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 |
42 | function setAsyncActorKeys <T extends MActor> (actor: T) { | 42 | async 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 | ||
55 | function getOrCreateActorAndServerAndModel ( | 51 | function getOrCreateActorAndServerAndModel ( |
@@ -346,7 +342,7 @@ async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannel | |||
346 | export { | 342 | export { |
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 @@ | |||
1 | import * as Bull from 'bull' | ||
2 | import { generateAndSaveActorKeys } from '@server/lib/activitypub/actor' | ||
3 | import { ActorModel } from '@server/models/activitypub/actor' | ||
4 | import { ActorKeysPayload } from '@shared/models' | ||
5 | import { logger } from '../../../helpers/logger' | ||
6 | |||
7 | async 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 | |||
18 | export { | ||
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 | |||
25 | import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' | 26 | import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' |
26 | import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' | 27 | import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' |
27 | import { refreshAPObject } from './handlers/activitypub-refresher' | 28 | import { refreshAPObject } from './handlers/activitypub-refresher' |
29 | import { processActorKeys } from './handlers/actor-keys' | ||
28 | import { processEmail } from './handlers/email' | 30 | import { processEmail } from './handlers/email' |
29 | import { processVideoFileImport } from './handlers/video-file-import' | 31 | import { processVideoFileImport } from './handlers/video-file-import' |
30 | import { processVideoImport } from './handlers/video-import' | 32 | import { 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 | ||
49 | type CreateJobOptions = { | 52 | type 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 | |||
10 | import { ActorModel } from '../models/activitypub/actor' | 10 | import { ActorModel } from '../models/activitypub/actor' |
11 | import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models' | 11 | import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models' |
12 | import { MUser, MUserDefault, MUserId } from '../types/models/user' | 12 | import { MUser, MUserDefault, MUserId } from '../types/models/user' |
13 | import { buildActorInstance, setAsyncActorKeys } from './activitypub/actor' | 13 | import { buildActorInstance, generateAndSaveActorKeys } from './activitypub/actor' |
14 | import { getLocalAccountActivityPubUrl } from './activitypub/url' | 14 | import { getLocalAccountActivityPubUrl } from './activitypub/url' |
15 | import { Emailer } from './emailer' | 15 | import { Emailer } from './emailer' |
16 | import { LiveManager } from './live-manager' | 16 | import { 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 | } |