X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjobs%2Factivitypub-http-job-scheduler%2Factivitypub-http-unicast-handler.ts;h=e02bd698e53bbcddcfb035db5aa80986e28a67fc;hb=60650c77c8a2a98e92d869b237ae4900f369a8fc;hp=f7f3dabbd383be0e852f8483c3672d8885f7aeb8;hpb=0032ebe94aa83fab761c7de3ceb6210ac4532824;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts index f7f3dabbd..e02bd698e 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts @@ -1,27 +1,31 @@ -import { logger } from '../../../helpers' +import { logger } from '../../../helpers/logger' import { doRequest } from '../../../helpers/requests' -import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler' -import { database as db } from '../../../initializers/database' -import { buildSignedActivity } from '../../../helpers/activitypub' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' +import { ActivityPubHttpPayload, buildSignedRequestOptions, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' async function process (payload: ActivityPubHttpPayload, jobId: number) { logger.info('Processing ActivityPub unicast in job %d.', jobId) - const accountSignature = await db.Account.load(payload.signatureAccountId) - if (!accountSignature) throw new Error('Unknown signature account id.') + const body = await computeBody(payload) + const httpSignatureOptions = await buildSignedRequestOptions(payload) - const signedBody = await buildSignedActivity(accountSignature, payload.body) const uri = payload.uris[0] const options = { method: 'POST', uri, - json: signedBody + json: body, + httpSignature: httpSignatureOptions } try { await doRequest(options) + await ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([ uri ], [], undefined) } catch (err) { - await maybeRetryRequestLater(err, payload, uri) + const isRetryingLater = await maybeRetryRequestLater(err, payload, uri) + if (isRetryingLater === false) { + await ActorFollowModel.updateActorFollowsScoreAndRemoveBadOnes([], [ uri ], undefined) + } + throw err } }