]>
Commit | Line | Data |
---|---|---|
1 | import * as Bull from 'bull' | |
2 | import { ActivitypubHttpUnicastPayload } from '@shared/models' | |
3 | import { logger } from '../../../helpers/logger' | |
4 | import { doRequest } from '../../../helpers/requests' | |
5 | import { REQUEST_TIMEOUT } from '../../../initializers/constants' | |
6 | import { ActorFollowScoreCache } from '../../files-cache' | |
7 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' | |
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' as 'POST', | |
20 | json: body, | |
21 | httpSignature: httpSignatureOptions, | |
22 | timeout: REQUEST_TIMEOUT, | |
23 | headers: buildGlobalHeaders(body) | |
24 | } | |
25 | ||
26 | try { | |
27 | await doRequest(uri, options) | |
28 | ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], []) | |
29 | } catch (err) { | |
30 | ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ]) | |
31 | ||
32 | throw err | |
33 | } | |
34 | } | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | ||
38 | export { | |
39 | processActivityPubHttpUnicast | |
40 | } |