]>
Commit | Line | Data |
---|---|---|
94831479 | 1 | import * as Bull from 'bull' |
f55e5a7b | 2 | import * as Bluebird from 'bluebird' |
da854ddd C |
3 | import { logger } from '../../../helpers/logger' |
4 | import { doRequest } from '../../../helpers/requests' | |
60650c77 | 5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
729bb184 | 6 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' |
71e3dfda | 7 | import { BROADCAST_CONCURRENCY, JOB_REQUEST_TIMEOUT } from '../../../initializers' |
afffe988 | 8 | |
94a5ff8a C |
9 | export type ActivitypubHttpBroadcastPayload = { |
10 | uris: string[] | |
11 | signatureActorId?: number | |
12 | body: any | |
13 | } | |
14 | ||
94831479 | 15 | async function processActivityPubHttpBroadcast (job: Bull.Job) { |
94a5ff8a C |
16 | logger.info('Processing ActivityPub broadcast in job %d.', job.id) |
17 | ||
18 | const payload = job.data as ActivitypubHttpBroadcastPayload | |
afffe988 | 19 | |
63c93323 | 20 | const body = await computeBody(payload) |
e12a0092 | 21 | const httpSignatureOptions = await buildSignedRequestOptions(payload) |
afffe988 C |
22 | |
23 | const options = { | |
24 | method: 'POST', | |
25 | uri: '', | |
e12a0092 | 26 | json: body, |
71e3dfda | 27 | httpSignature: httpSignatureOptions, |
729bb184 C |
28 | timeout: JOB_REQUEST_TIMEOUT, |
29 | headers: buildGlobalHeaders(body) | |
afffe988 C |
30 | } |
31 | ||
60650c77 C |
32 | const badUrls: string[] = [] |
33 | const goodUrls: string[] = [] | |
34 | ||
f55e5a7b C |
35 | await Bluebird.map(payload.uris, uri => { |
36 | return doRequest(Object.assign({}, options, { uri })) | |
37 | .then(() => goodUrls.push(uri)) | |
38 | .catch(() => badUrls.push(uri)) | |
39 | }, { concurrency: BROADCAST_CONCURRENCY }) | |
60650c77 | 40 | |
2e3a0215 | 41 | return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined) |
afffe988 C |
42 | } |
43 | ||
afffe988 C |
44 | // --------------------------------------------------------------------------- |
45 | ||
46 | export { | |
94a5ff8a | 47 | processActivityPubHttpBroadcast |
afffe988 | 48 | } |