]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/activitypub/inbox.ts
Move apicache in peertube
[github/Chocobozzz/PeerTube.git] / server / controllers / activitypub / inbox.ts
index 67b2c0d66769a2304f5bc78cd9189b0289834dad..30662990a0e628e9025de95ff4e59eb95fffd374 100644 (file)
@@ -1,13 +1,11 @@
 import * as express from 'express'
+import { InboxManager } from '@server/lib/activitypub/inbox-manager'
 import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared'
+import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
 import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
 import { logger } from '../../helpers/logger'
-import { processActivities } from '../../lib/activitypub/process/process'
 import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'
 import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
-import { queue } from 'async'
-import { MActorDefault, MActorSignature } from '../../types/models'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
 const inboxRouter = express.Router()
 
@@ -41,18 +39,6 @@ export {
 
 // ---------------------------------------------------------------------------
 
-type QueueParam = { activities: Activity[], signatureActor?: MActorSignature, inboxActor?: MActorDefault }
-const inboxQueue = queue<QueueParam, Error>((task, cb) => {
-  const options = { signatureActor: task.signatureActor, inboxActor: task.inboxActor }
-
-  processActivities(task.activities, options)
-    .then(() => cb())
-    .catch(err => {
-      logger.error('Error in process activities.', { err })
-      cb()
-    })
-})
-
 function inboxController (req: express.Request, res: express.Response) {
   const rootActivity: RootActivity = req.body
   let activities: Activity[]
@@ -74,10 +60,12 @@ function inboxController (req: express.Request, res: express.Response) {
 
   logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
 
-  inboxQueue.push({
+  InboxManager.Instance.addInboxMessage({
     activities,
     signatureActor: res.locals.signature.actor,
-    inboxActor: accountOrChannel ? accountOrChannel.Actor : undefined
+    inboxActor: accountOrChannel
+      ? accountOrChannel.Actor
+      : undefined
   })
 
   return res.status(HttpStatusCode.NO_CONTENT_204).end()