]>
Commit | Line | Data |
---|---|---|
94a5ff8a | 1 | import * as kue from 'kue' |
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' |
94a5ff8a | 6 | import { 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 | ||
15 | async function processActivityPubHttpBroadcast (job: kue.Job) { | |
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 C |
27 | httpSignature: httpSignatureOptions, |
28 | timeout: JOB_REQUEST_TIMEOUT | |
afffe988 C |
29 | } |
30 | ||
60650c77 C |
31 | const badUrls: string[] = [] |
32 | const goodUrls: string[] = [] | |
33 | ||
f55e5a7b C |
34 | await Bluebird.map(payload.uris, uri => { |
35 | return doRequest(Object.assign({}, options, { uri })) | |
36 | .then(() => goodUrls.push(uri)) | |
37 | .catch(() => badUrls.push(uri)) | |
38 | }, { concurrency: BROADCAST_CONCURRENCY }) | |
60650c77 | 39 | |
2e3a0215 | 40 | return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined) |
afffe988 C |
41 | } |
42 | ||
afffe988 C |
43 | // --------------------------------------------------------------------------- |
44 | ||
45 | export { | |
94a5ff8a | 46 | processActivityPubHttpBroadcast |
afffe988 | 47 | } |