aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-broadcast.ts2
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-unicast.ts2
-rw-r--r--server/lib/job-queue/handlers/utils/activitypub-http-utils.ts59
3 files changed, 2 insertions, 61 deletions
diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
index fbf01d276..709e8501f 100644
--- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
@@ -1,11 +1,11 @@
1import { map } from 'bluebird' 1import { map } from 'bluebird'
2import { Job } from 'bull' 2import { Job } from 'bull'
3import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send'
3import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' 4import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache'
4import { ActivitypubHttpBroadcastPayload } from '@shared/models' 5import { ActivitypubHttpBroadcastPayload } from '@shared/models'
5import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
6import { doRequest } from '../../../helpers/requests' 7import { doRequest } from '../../../helpers/requests'
7import { BROADCAST_CONCURRENCY } from '../../../initializers/constants' 8import { BROADCAST_CONCURRENCY } from '../../../initializers/constants'
8import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
9 9
10async function processActivityPubHttpBroadcast (job: Job) { 10async function processActivityPubHttpBroadcast (job: Job) {
11 logger.info('Processing ActivityPub broadcast in job %d.', job.id) 11 logger.info('Processing ActivityPub broadcast in job %d.', job.id)
diff --git a/server/lib/job-queue/handlers/activitypub-http-unicast.ts b/server/lib/job-queue/handlers/activitypub-http-unicast.ts
index 673583d2b..99bcd3e8d 100644
--- a/server/lib/job-queue/handlers/activitypub-http-unicast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-unicast.ts
@@ -1,9 +1,9 @@
1import { Job } from 'bull' 1import { Job } from 'bull'
2import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send'
2import { ActivitypubHttpUnicastPayload } from '@shared/models' 3import { ActivitypubHttpUnicastPayload } from '@shared/models'
3import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
4import { doRequest } from '../../../helpers/requests' 5import { doRequest } from '../../../helpers/requests'
5import { ActorFollowHealthCache } from '../../actor-follow-health-cache' 6import { ActorFollowHealthCache } from '../../actor-follow-health-cache'
6import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
7 7
8async function processActivityPubHttpUnicast (job: Job) { 8async function processActivityPubHttpUnicast (job: Job) {
9 logger.info('Processing ActivityPub unicast in job %d.', job.id) 9 logger.info('Processing ActivityPub unicast in job %d.', job.id)
diff --git a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
deleted file mode 100644
index 2a03325b7..000000000
--- a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
+++ /dev/null
@@ -1,59 +0,0 @@
1import { buildDigest } from '@server/helpers/peertube-crypto'
2import { buildSignedActivity } from '@server/lib/activitypub/activity'
3import { getServerActor } from '@server/models/application/application'
4import { ContextType } from '@shared/models/activitypub/context'
5import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants'
6import { ActorModel } from '../../../../models/actor/actor'
7import { MActor } from '../../../../types/models'
8
9type Payload <T> = { body: T, contextType?: ContextType, signatureActorId?: number }
10
11async function computeBody <T> (
12 payload: Payload<T>
13): Promise<T | T & { type: 'RsaSignature2017', creator: string, created: string }> {
14 let body = payload.body
15
16 if (payload.signatureActorId) {
17 const actorSignature = await ActorModel.load(payload.signatureActorId)
18 if (!actorSignature) throw new Error('Unknown signature actor id.')
19
20 body = await buildSignedActivity(actorSignature, payload.body, payload.contextType)
21 }
22
23 return body
24}
25
26async function buildSignedRequestOptions (payload: Payload<any>) {
27 let actor: MActor | null
28
29 if (payload.signatureActorId) {
30 actor = await ActorModel.load(payload.signatureActorId)
31 if (!actor) throw new Error('Unknown signature actor id.')
32 } else {
33 // We need to sign the request, so use the server
34 actor = await getServerActor()
35 }
36
37 const keyId = actor.url
38 return {
39 algorithm: HTTP_SIGNATURE.ALGORITHM,
40 authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
41 keyId,
42 key: actor.privateKey,
43 headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
44 }
45}
46
47function buildGlobalHeaders (body: any) {
48 return {
49 'digest': buildDigest(body),
50 'content-type': 'application/activity+json',
51 'accept': ACTIVITY_PUB.ACCEPT_HEADER
52 }
53}
54
55export {
56 buildGlobalHeaders,
57 computeBody,
58 buildSignedRequestOptions
59}