]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/activitypub/inbox.ts
Bufferize videos views in redis
[github/Chocobozzz/PeerTube.git] / server / controllers / activitypub / inbox.ts
index a106df717f0847598a8d8d0d1a34609b97fcda49..20bd20ed451e3d095b79fe2807f2e5eea070254e 100644 (file)
@@ -3,9 +3,10 @@ import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActi
 import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
 import { logger } from '../../helpers/logger'
 import { processActivities } from '../../lib/activitypub/process/process'
-import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares'
+import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'
 import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
-import { ActorModel } from '../../models/activitypub/actor'
+import { VideoChannelModel } from '../../models/video/video-channel'
+import { AccountModel } from '../../models/account/account'
 
 const inboxRouter = express.Router()
 
@@ -23,6 +24,13 @@ inboxRouter.post('/accounts/:name/inbox',
   asyncMiddleware(activityPubValidator),
   asyncMiddleware(inboxController)
 )
+inboxRouter.post('/video-channels/:name/inbox',
+  signatureValidator,
+  asyncMiddleware(checkSignature),
+  asyncMiddleware(localVideoChannelValidator),
+  asyncMiddleware(activityPubValidator),
+  asyncMiddleware(inboxController)
+)
 
 // ---------------------------------------------------------------------------
 
@@ -49,16 +57,16 @@ async function inboxController (req: express.Request, res: express.Response, nex
   activities = activities.filter(a => isActivityValid(a))
   logger.debug('We keep %d activities.', activities.length, { activities })
 
-  let specificActor: ActorModel = undefined
+  let accountOrChannel: VideoChannelModel | AccountModel
   if (res.locals.account) {
-    specificActor = res.locals.account
+    accountOrChannel = res.locals.account
   } else if (res.locals.videoChannel) {
-    specificActor = res.locals.videoChannel
+    accountOrChannel = res.locals.videoChannel
   }
 
   logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
 
-  await processActivities(activities, res.locals.signature.actor, specificActor)
+  await processActivities(activities, res.locals.signature.actor, accountOrChannel ? accountOrChannel.Actor : undefined)
 
   res.status(204).end()
 }