aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts16
-rw-r--r--server/controllers/activitypub/inbox.ts23
2 files changed, 28 insertions, 11 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 2e168ea78..6229c44aa 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -6,7 +6,13 @@ import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
6import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send' 6import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send'
7import { audiencify, getAudience } from '../../lib/activitypub/audience' 7import { audiencify, getAudience } from '../../lib/activitypub/audience'
8import { buildCreateActivity } from '../../lib/activitypub/send/send-create' 8import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
9import { asyncMiddleware, executeIfActivityPub, localAccountValidator, localVideoChannelValidator } from '../../middlewares' 9import {
10 asyncMiddleware,
11 executeIfActivityPub,
12 localAccountValidator,
13 localVideoChannelValidator,
14 videosCustomGetValidator
15} from '../../middlewares'
10import { videosGetValidator, videosShareValidator } from '../../middlewares/validators' 16import { videosGetValidator, videosShareValidator } from '../../middlewares/validators'
11import { videoCommentGetValidator } from '../../middlewares/validators/video-comments' 17import { videoCommentGetValidator } from '../../middlewares/validators/video-comments'
12import { AccountModel } from '../../models/account/account' 18import { AccountModel } from '../../models/account/account'
@@ -54,7 +60,7 @@ activityPubClientRouter.get('/videos/watch/:id/activity',
54 executeIfActivityPub(asyncMiddleware(videoController)) 60 executeIfActivityPub(asyncMiddleware(videoController))
55) 61)
56activityPubClientRouter.get('/videos/watch/:id/announces', 62activityPubClientRouter.get('/videos/watch/:id/announces',
57 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 63 executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
58 executeIfActivityPub(asyncMiddleware(videoAnnouncesController)) 64 executeIfActivityPub(asyncMiddleware(videoAnnouncesController))
59) 65)
60activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', 66activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
@@ -62,15 +68,15 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
62 executeIfActivityPub(asyncMiddleware(videoAnnounceController)) 68 executeIfActivityPub(asyncMiddleware(videoAnnounceController))
63) 69)
64activityPubClientRouter.get('/videos/watch/:id/likes', 70activityPubClientRouter.get('/videos/watch/:id/likes',
65 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 71 executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
66 executeIfActivityPub(asyncMiddleware(videoLikesController)) 72 executeIfActivityPub(asyncMiddleware(videoLikesController))
67) 73)
68activityPubClientRouter.get('/videos/watch/:id/dislikes', 74activityPubClientRouter.get('/videos/watch/:id/dislikes',
69 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 75 executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
70 executeIfActivityPub(asyncMiddleware(videoDislikesController)) 76 executeIfActivityPub(asyncMiddleware(videoDislikesController))
71) 77)
72activityPubClientRouter.get('/videos/watch/:id/comments', 78activityPubClientRouter.get('/videos/watch/:id/comments',
73 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 79 executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))),
74 executeIfActivityPub(asyncMiddleware(videoCommentsController)) 80 executeIfActivityPub(asyncMiddleware(videoCommentsController))
75) 81)
76activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', 82activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
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}