]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/job-queue/handlers/activitypub-http-unicast.ts
Update http signature
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-http-unicast.ts
1 import * as Bull from 'bull'
2 import { logger } from '../../../helpers/logger'
3 import { doRequest } from '../../../helpers/requests'
4 import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
5 import { JOB_REQUEST_TIMEOUT } from '../../../initializers/constants'
6 import { ActorFollowScoreCache } from '../../files-cache'
7
8 export type ActivitypubHttpUnicastPayload = {
9 uri: string
10 signatureActorId?: number
11 body: any
12 }
13
14 async function processActivityPubHttpUnicast (job: Bull.Job) {
15 logger.info('Processing ActivityPub unicast in job %d.', job.id)
16
17 const payload = job.data as ActivitypubHttpUnicastPayload
18 const uri = payload.uri
19
20 const body = await computeBody(payload)
21 const httpSignatureOptions = await buildSignedRequestOptions(payload)
22
23 logger.info('hello', { httpSignatureOptions })
24
25 const options = {
26 method: 'POST',
27 uri,
28 json: body,
29 httpSignature: httpSignatureOptions,
30 timeout: JOB_REQUEST_TIMEOUT,
31 headers: buildGlobalHeaders(body)
32 }
33
34 try {
35 await doRequest(options)
36 ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], [])
37 } catch (err) {
38 ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ])
39
40 throw err
41 }
42 }
43
44 // ---------------------------------------------------------------------------
45
46 export {
47 processActivityPubHttpUnicast
48 }