aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/activitypub/inbox.ts23
1 files changed, 17 insertions, 6 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index 20bd20ed4..738d155eb 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -7,6 +7,8 @@ import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChann
7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
8import { VideoChannelModel } from '../../models/video/video-channel' 8import { VideoChannelModel } from '../../models/video/video-channel'
9import { AccountModel } from '../../models/account/account' 9import { AccountModel } from '../../models/account/account'
10import { queue } from 'async'
11import { ActorModel } from '../../models/activitypub/actor'
10 12
11const inboxRouter = express.Router() 13const inboxRouter = express.Router()
12 14
@@ -14,7 +16,7 @@ inboxRouter.post('/inbox',
14 signatureValidator, 16 signatureValidator,
15 asyncMiddleware(checkSignature), 17 asyncMiddleware(checkSignature),
16 asyncMiddleware(activityPubValidator), 18 asyncMiddleware(activityPubValidator),
17 asyncMiddleware(inboxController) 19 inboxController
18) 20)
19 21
20inboxRouter.post('/accounts/:name/inbox', 22inboxRouter.post('/accounts/:name/inbox',
@@ -22,14 +24,14 @@ inboxRouter.post('/accounts/:name/inbox',
22 asyncMiddleware(checkSignature), 24 asyncMiddleware(checkSignature),
23 asyncMiddleware(localAccountValidator), 25 asyncMiddleware(localAccountValidator),
24 asyncMiddleware(activityPubValidator), 26 asyncMiddleware(activityPubValidator),
25 asyncMiddleware(inboxController) 27 inboxController
26) 28)
27inboxRouter.post('/video-channels/:name/inbox', 29inboxRouter.post('/video-channels/:name/inbox',
28 signatureValidator, 30 signatureValidator,
29 asyncMiddleware(checkSignature), 31 asyncMiddleware(checkSignature),
30 asyncMiddleware(localVideoChannelValidator), 32 asyncMiddleware(localVideoChannelValidator),
31 asyncMiddleware(activityPubValidator), 33 asyncMiddleware(activityPubValidator),
32 asyncMiddleware(inboxController) 34 inboxController
33) 35)
34 36
35// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------
@@ -40,7 +42,12 @@ export {
40 42
41// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
42 44
43async function inboxController (req: express.Request, res: express.Response, next: express.NextFunction) { 45const inboxQueue = queue<{ activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel }, Error>((task, cb) => {
46 processActivities(task.activities, task.signatureActor, task.inboxActor)
47 .then(() => cb())
48})
49
50function inboxController (req: express.Request, res: express.Response, next: express.NextFunction) {
44 const rootActivity: RootActivity = req.body 51 const rootActivity: RootActivity = req.body
45 let activities: Activity[] = [] 52 let activities: Activity[] = []
46 53
@@ -66,7 +73,11 @@ async function inboxController (req: express.Request, res: express.Response, nex
66 73
67 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url) 74 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
68 75
69 await processActivities(activities, res.locals.signature.actor, accountOrChannel ? accountOrChannel.Actor : undefined) 76 inboxQueue.push({
77 activities,
78 signatureActor: res.locals.signature.actor,
79 inboxActor: accountOrChannel ? accountOrChannel.Actor : undefined
80 })
70 81
71 res.status(204).end() 82 return res.status(204).end()
72} 83}