1 import { Job } from 'bull'
2 import { ActivitypubHttpUnicastPayload } from '@shared/models'
3 import { logger } from '../../../helpers/logger'
4 import { doRequest } from '../../../helpers/requests'
5 import { ActorFollowHealthCache } from '../../actor-follow-health-cache'
6 import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
8 async function processActivityPubHttpUnicast (job: Job) {
9 logger.info('Processing ActivityPub unicast in job %d.', job.id)
11 const payload = job.data as ActivitypubHttpUnicastPayload
12 const uri = payload.uri
14 const body = await computeBody(payload)
15 const httpSignatureOptions = await buildSignedRequestOptions(payload)
18 method: 'POST' as 'POST',
20 httpSignature: httpSignatureOptions,
21 headers: buildGlobalHeaders(body)
25 await doRequest(uri, options)
26 ActorFollowHealthCache.Instance.updateActorFollowsHealth([ uri ], [])
28 ActorFollowHealthCache.Instance.updateActorFollowsHealth([], [ uri ])
34 // ---------------------------------------------------------------------------
37 processActivityPubHttpUnicast