diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-14 16:47:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-14 16:47:15 +0200 |
commit | d61b817890d5d5bba61d447518321870498028d8 (patch) | |
tree | 5479ec937fff967bddf7b7f404a8a733e89f77d4 /server | |
parent | 4b5384f6e7be62d072d21d8d964951ba572ab10e (diff) | |
download | PeerTube-d61b817890d5d5bba61d447518321870498028d8.tar.gz PeerTube-d61b817890d5d5bba61d447518321870498028d8.tar.zst PeerTube-d61b817890d5d5bba61d447518321870498028d8.zip |
Process inbox activities in a queue
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 23 |
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 | |||
7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
8 | import { VideoChannelModel } from '../../models/video/video-channel' | 8 | import { VideoChannelModel } from '../../models/video/video-channel' |
9 | import { AccountModel } from '../../models/account/account' | 9 | import { AccountModel } from '../../models/account/account' |
10 | import { queue } from 'async' | ||
11 | import { ActorModel } from '../../models/activitypub/actor' | ||
10 | 12 | ||
11 | const inboxRouter = express.Router() | 13 | const 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 | ||
20 | inboxRouter.post('/accounts/:name/inbox', | 22 | inboxRouter.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 | ) |
27 | inboxRouter.post('/video-channels/:name/inbox', | 29 | inboxRouter.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 | ||
43 | async function inboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 45 | const inboxQueue = queue<{ activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel }, Error>((task, cb) => { |
46 | processActivities(task.activities, task.signatureActor, task.inboxActor) | ||
47 | .then(() => cb()) | ||
48 | }) | ||
49 | |||
50 | function 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 | } |