]>
Commit | Line | Data |
---|---|---|
94831479 | 1 | import * as Bull from 'bull' |
94a5ff8a C |
2 | import { logger } from '../../../helpers/logger' |
3 | import { doRequest } from '../../../helpers/requests' | |
4 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |
5 | import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' | |
71e3dfda | 6 | import { JOB_REQUEST_TIMEOUT } from '../../../initializers' |
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 C |
27 | httpSignature: httpSignatureOptions, |
28 | timeout: JOB_REQUEST_TIMEOUT | |
94a5ff8a C |
29 | } |
30 | ||
31 | try { | |
32 | await doRequest(options) | |
2e3a0215 | 33 | ActorFollowModel.updateActorFollowsScore([ uri ], [], undefined) |
94a5ff8a | 34 | } catch (err) { |
2e3a0215 | 35 | ActorFollowModel.updateActorFollowsScore([], [ uri ], undefined) |
94a5ff8a C |
36 | |
37 | throw err | |
38 | } | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | export { | |
44 | processActivityPubHttpUnicast | |
45 | } |