]>
Commit | Line | Data |
---|---|---|
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 | import { ActivitypubHttpUnicastPayload } from '@shared/models' | |
8 | ||
9 | async function processActivityPubHttpUnicast (job: Bull.Job) { | |
10 | logger.info('Processing ActivityPub unicast in job %d.', job.id) | |
11 | ||
12 | const payload = job.data as ActivitypubHttpUnicastPayload | |
13 | const uri = payload.uri | |
14 | ||
15 | const body = await computeBody(payload) | |
16 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | |
17 | ||
18 | const options = { | |
19 | method: 'POST', | |
20 | uri, | |
21 | json: body, | |
22 | httpSignature: httpSignatureOptions, | |
23 | timeout: JOB_REQUEST_TIMEOUT, | |
24 | headers: buildGlobalHeaders(body) | |
25 | } | |
26 | ||
27 | try { | |
28 | await doRequest(options) | |
29 | ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], []) | |
30 | } catch (err) { | |
31 | ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ]) | |
32 | ||
33 | throw err | |
34 | } | |
35 | } | |
36 | ||
37 | // --------------------------------------------------------------------------- | |
38 | ||
39 | export { | |
40 | processActivityPubHttpUnicast | |
41 | } |