]>
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' | |
6 | import { ActorFollowScoreCache } from '../../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 | const options = { | |
24 | method: 'POST', | |
25 | uri, | |
26 | json: body, | |
27 | httpSignature: httpSignatureOptions, | |
28 | timeout: JOB_REQUEST_TIMEOUT, | |
29 | headers: buildGlobalHeaders(body) | |
30 | } | |
31 | ||
32 | try { | |
33 | await doRequest(options) | |
34 | ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], []) | |
35 | } catch (err) { | |
36 | ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ]) | |
37 | ||
38 | throw err | |
39 | } | |
40 | } | |
41 | ||
42 | // --------------------------------------------------------------------------- | |
43 | ||
44 | export { | |
45 | processActivityPubHttpUnicast | |
46 | } |