1 import * as Bull from 'bull'
2 import { logger } from '../../../helpers/logger'
3 import { doRequest } from '../../../helpers/requests'
4 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5 import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
6 import { JOB_REQUEST_TIMEOUT } from '../../../initializers'
8 export type ActivitypubHttpUnicastPayload = {
10 signatureActorId?: number
14 async function processActivityPubHttpUnicast (job: Bull.Job) {
15 logger.info('Processing ActivityPub unicast in job %d.', job.id)
17 const payload = job.data as ActivitypubHttpUnicastPayload
18 const uri = payload.uri
20 const body = await computeBody(payload)
21 const httpSignatureOptions = await buildSignedRequestOptions(payload)
27 httpSignature: httpSignatureOptions,
28 timeout: JOB_REQUEST_TIMEOUT,
29 headers: buildGlobalHeaders(body)
33 await doRequest(options)
34 ActorFollowModel.updateActorFollowsScore([ uri ], [], undefined)
36 ActorFollowModel.updateActorFollowsScore([], [ uri ], undefined)
42 // ---------------------------------------------------------------------------
45 processActivityPubHttpUnicast