]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/job-queue/handlers/activitypub-http-unicast.ts
Check live duration and size
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-http-unicast.ts
CommitLineData
94831479 1import * as Bull from 'bull'
94a5ff8a
C
2import { logger } from '../../../helpers/logger'
3import { doRequest } from '../../../helpers/requests'
729bb184 4import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
74dc3bca 5import { JOB_REQUEST_TIMEOUT } from '../../../initializers/constants'
d74d29ad 6import { ActorFollowScoreCache } from '../../files-cache'
8dc8a34e 7import { ActivitypubHttpUnicastPayload } from '@shared/models'
94a5ff8a 8
94831479 9async function processActivityPubHttpUnicast (job: Bull.Job) {
94a5ff8a
C
10 logger.info('Processing ActivityPub unicast in job %d.', job.id)
11
12 const payload = job.data as ActivitypubHttpUnicastPayload
13 const uri = payload.uri
14
15 const body = await computeBody(payload)
16 const httpSignatureOptions = await buildSignedRequestOptions(payload)
17
18 const options = {
19 method: 'POST',
20 uri,
21 json: body,
71e3dfda 22 httpSignature: httpSignatureOptions,
729bb184
C
23 timeout: JOB_REQUEST_TIMEOUT,
24 headers: buildGlobalHeaders(body)
94a5ff8a
C
25 }
26
27 try {
28 await doRequest(options)
2f5c6b2f 29 ActorFollowScoreCache.Instance.updateActorFollowsScore([ uri ], [])
94a5ff8a 30 } catch (err) {
2f5c6b2f 31 ActorFollowScoreCache.Instance.updateActorFollowsScore([], [ uri ])
94a5ff8a
C
32
33 throw err
34 }
35}
36
37// ---------------------------------------------------------------------------
38
39export {
40 processActivityPubHttpUnicast
41}