]>
Commit | Line | Data |
---|---|---|
1 | import * as Bluebird from 'bluebird' | |
2 | import * as Bull from 'bull' | |
3 | import { ActivitypubHttpBroadcastPayload } from '@shared/models' | |
4 | import { logger } from '../../../helpers/logger' | |
5 | import { doRequest } from '../../../helpers/requests' | |
6 | import { BROADCAST_CONCURRENCY } from '../../../initializers/constants' | |
7 | import { ActorFollowScoreCache } from '../../files-cache' | |
8 | import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' | |
9 | ||
10 | async function processActivityPubHttpBroadcast (job: Bull.Job) { | |
11 | logger.info('Processing ActivityPub broadcast in job %d.', job.id) | |
12 | ||
13 | const payload = job.data as ActivitypubHttpBroadcastPayload | |
14 | ||
15 | const body = await computeBody(payload) | |
16 | const httpSignatureOptions = await buildSignedRequestOptions(payload) | |
17 | ||
18 | const options = { | |
19 | method: 'POST' as 'POST', | |
20 | json: body, | |
21 | httpSignature: httpSignatureOptions, | |
22 | headers: buildGlobalHeaders(body) | |
23 | } | |
24 | ||
25 | const badUrls: string[] = [] | |
26 | const goodUrls: string[] = [] | |
27 | ||
28 | await Bluebird.map(payload.uris, uri => { | |
29 | return doRequest(uri, options) | |
30 | .then(() => goodUrls.push(uri)) | |
31 | .catch(() => badUrls.push(uri)) | |
32 | }, { concurrency: BROADCAST_CONCURRENCY }) | |
33 | ||
34 | return ActorFollowScoreCache.Instance.updateActorFollowsScore(goodUrls, badUrls) | |
35 | } | |
36 | ||
37 | // --------------------------------------------------------------------------- | |
38 | ||
39 | export { | |
40 | processActivityPubHttpBroadcast | |
41 | } |