]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-http-unicast.ts
Use worker thread to send HTTP requests
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-http-unicast.ts
CommitLineData
5a921e7b 1import { Job } from 'bullmq'
a219c910 2import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from '@server/lib/activitypub/send'
dcd75f78 3import { ActivitypubHttpUnicastPayload } from '@shared/models'
94a5ff8a
C
4import { logger } from '../../../helpers/logger'
5import { doRequest } from '../../../helpers/requests'
9db437c8 6import { ActorFollowHealthCache } from '../../actor-follow-health-cache'
94a5ff8a 7
41fb13c3 8async function processActivityPubHttpUnicast (job: Job) {
bd911b54 9 logger.info('Processing ActivityPub unicast in job %s.', job.id)
94a5ff8a
C
10
11 const payload = job.data as ActivitypubHttpUnicastPayload
12 const uri = payload.uri
13
14 const body = await computeBody(payload)
15 const httpSignatureOptions = await buildSignedRequestOptions(payload)
16
17 const options = {
db4b15f2 18 method: 'POST' as 'POST',
94a5ff8a 19 json: body,
71e3dfda 20 httpSignature: httpSignatureOptions,
729bb184 21 headers: buildGlobalHeaders(body)
94a5ff8a
C
22 }
23
24 try {
db4b15f2 25 await doRequest(uri, options)
9db437c8 26 ActorFollowHealthCache.Instance.updateActorFollowsHealth([ uri ], [])
94a5ff8a 27 } catch (err) {
9db437c8 28 ActorFollowHealthCache.Instance.updateActorFollowsHealth([], [ uri ])
94a5ff8a
C
29
30 throw err
31 }
32}
33
34// ---------------------------------------------------------------------------
35
36export {
37 processActivityPubHttpUnicast
38}