]>
Commit | Line | Data |
---|---|---|
41fb13c3 C |
1 | import { map } from 'bluebird' |
2 | import { Job } from 'bull' | |
9db437c8 | 3 | import { ActorFollowHealthCache } from '@server/lib/actor-follow-health-cache' |
dcd75f78 | 4 | import { ActivitypubHttpBroadcastPayload } from '@shared/models' |
da854ddd C |
5 | import { logger } from '../../../helpers/logger' |
6 | import { doRequest } from '../../../helpers/requests' | |
7500d6c9 | 7 | import { BROADCAST_CONCURRENCY } from '../../../initializers/constants' |
dcd75f78 | 8 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' |
94a5ff8a | 9 | |
41fb13c3 | 10 | async function processActivityPubHttpBroadcast (job: Job) { |
94a5ff8a C |
11 | logger.info('Processing ActivityPub broadcast in job %d.', job.id) |
12 | ||
13 | const payload = job.data as ActivitypubHttpBroadcastPayload | |
afffe988 | 14 | |
63c93323 | 15 | const body = await computeBody(payload) |
e12a0092 | 16 | const httpSignatureOptions = await buildSignedRequestOptions(payload) |
afffe988 C |
17 | |
18 | const options = { | |
db4b15f2 | 19 | method: 'POST' as 'POST', |
e12a0092 | 20 | json: body, |
71e3dfda | 21 | httpSignature: httpSignatureOptions, |
729bb184 | 22 | headers: buildGlobalHeaders(body) |
afffe988 C |
23 | } |
24 | ||
60650c77 C |
25 | const badUrls: string[] = [] |
26 | const goodUrls: string[] = [] | |
27 | ||
9db437c8 C |
28 | await map(payload.uris, async uri => { |
29 | try { | |
30 | await doRequest(uri, options) | |
31 | goodUrls.push(uri) | |
32 | } catch (err) { | |
33 | logger.debug('HTTP broadcast to %s failed.', uri, { err }) | |
34 | badUrls.push(uri) | |
35 | } | |
f55e5a7b | 36 | }, { concurrency: BROADCAST_CONCURRENCY }) |
60650c77 | 37 | |
9db437c8 | 38 | return ActorFollowHealthCache.Instance.updateActorFollowsHealth(goodUrls, badUrls) |
afffe988 C |
39 | } |
40 | ||
afffe988 C |
41 | // --------------------------------------------------------------------------- |
42 | ||
43 | export { | |
94a5ff8a | 44 | processActivityPubHttpBroadcast |
afffe988 | 45 | } |