]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/job-queue/handlers/activitypub-http-unicast.ts
Don't fail on upload if we cannot generate thumbnail
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / activitypub-http-unicast.ts
1 import * as kue from 'kue'
2 import { logger } from '../../../helpers/logger'
3 import { doRequest } from '../../../helpers/requests'
4 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5 import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
6
7 export type ActivitypubHttpUnicastPayload = {
8 uri: string
9 signatureActorId?: number
10 body: any
11 }
12
13 async function processActivityPubHttpUnicast (job: kue.Job) {
14 logger.info('Processing ActivityPub unicast in job %d.', job.id)
15
16 const payload = job.data as ActivitypubHttpUnicastPayload
17 const uri = payload.uri
18
19 const body = await computeBody(payload)
20 const httpSignatureOptions = await buildSignedRequestOptions(payload)
21
22 const options = {
23 method: 'POST',
24 uri,
25 json: body,
26 httpSignature: httpSignatureOptions
27 }
28
29 try {
30 await doRequest(options)
31 ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([ uri ], [], undefined)
32 } catch (err) {
33 ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([], [ uri ], undefined)
34
35 throw err
36 }
37 }
38
39 // ---------------------------------------------------------------------------
40
41 export {
42 processActivityPubHttpUnicast
43 }