]>
Commit | Line | Data |
---|---|---|
94831479 | 1 | import * as Bull from 'bull' |
94a5ff8a C |
2 | import { logger } from '../../../helpers/logger' |
3 | import { doRequest } from '../../../helpers/requests' | |
729bb184 | 4 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' |
71e3dfda | 5 | import { JOB_REQUEST_TIMEOUT } from '../../../initializers' |
d74d29ad | 6 | import { ActorFollowScoreCache } from '../../files-cache' |
94a5ff8a C |
7 | |
8 | export type ActivitypubHttpUnicastPayload = { | |
9 | uri: string | |
10 | signatureActorId?: number | |
11 | body: any | |
12 | } | |
13 | ||
94831479 | 14 | async function processActivityPubHttpUnicast (job: Bull.Job) { |
94a5ff8a C |
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, | |
71e3dfda | 27 | httpSignature: httpSignatureOptions, |
729bb184 C |
28 | timeout: JOB_REQUEST_TIMEOUT, |
29 | headers: buildGlobalHeaders(body) | |
94a5ff8a C |
30 | } |
31 | ||
32 | try { | |
33 | await doRequest(options) | |
2f5c6b2f | 34 | ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], []) |
94a5ff8a | 35 | } catch (err) { |
2f5c6b2f | 36 | ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ]) |
94a5ff8a C |
37 | |
38 | throw err | |
39 | } | |
40 | } | |
41 | ||
42 | // --------------------------------------------------------------------------- | |
43 | ||
44 | export { | |
45 | processActivityPubHttpUnicast | |
46 | } |