]>
Commit | Line | Data |
---|---|---|
1 | import * as Bull from 'bull' | |
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' | |
6 | import { JOB_REQUEST_TIMEOUT } from '../../../initializers' | |
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 | } | |
30 | ||
31 | try { | |
32 | await doRequest(options) | |
33 | ActorFollowModel.updateActorFollowsScore([ uri ], [], undefined) | |
34 | } catch (err) { | |
35 | ActorFollowModel.updateActorFollowsScore([], [ uri ], undefined) | |
36 | ||
37 | throw err | |
38 | } | |
39 | } | |
40 | ||
41 | // --------------------------------------------------------------------------- | |
42 | ||
43 | export { | |
44 | processActivityPubHttpUnicast | |
45 | } |