]>
Commit | Line | Data |
---|---|---|
94831479 | 1 | import * as Bull from 'bull' |
dcd75f78 | 2 | import { ActivitypubHttpUnicastPayload } from '@shared/models' |
94a5ff8a C |
3 | import { logger } from '../../../helpers/logger' |
4 | import { doRequest } from '../../../helpers/requests' | |
d74d29ad | 5 | import { ActorFollowScoreCache } from '../../files-cache' |
dcd75f78 | 6 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' |
94a5ff8a | 7 | |
94831479 | 8 | async function processActivityPubHttpUnicast (job: Bull.Job) { |
94a5ff8a C |
9 | logger.info('Processing ActivityPub unicast in job %d.', job.id) |
10 | ||
11 | const payload = job.data as ActivitypubHttpUnicastPayload | |
12 | const uri = payload.uri | |
13 | ||
14 | const body = await computeBody(payload) | |
15 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | |
16 | ||
17 | const options = { | |
db4b15f2 | 18 | method: 'POST' as 'POST', |
94a5ff8a | 19 | json: body, |
71e3dfda | 20 | httpSignature: httpSignatureOptions, |
729bb184 | 21 | headers: buildGlobalHeaders(body) |
94a5ff8a C |
22 | } |
23 | ||
24 | try { | |
db4b15f2 | 25 | await doRequest(uri, options) |
2f5c6b2f | 26 | ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], []) |
94a5ff8a | 27 | } catch (err) { |
2f5c6b2f | 28 | ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ]) |
94a5ff8a C |
29 | |
30 | throw err | |
31 | } | |
32 | } | |
33 | ||
34 | // --------------------------------------------------------------------------- | |
35 | ||
36 | export { | |
37 | processActivityPubHttpUnicast | |
38 | } |