]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts
Add scores to follows and remove bad ones
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / activitypub-http-job-scheduler / activitypub-http-unicast-handler.ts
index f7f3dabbd383be0e852f8483c3672d8885f7aeb8..e02bd698e53bbcddcfb035db5aa80986e28a67fc 100644 (file)
@@ -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
   }
 }