aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/inbox.ts20
-rw-r--r--server/controllers/activitypub/outbox.ts14
2 files changed, 24 insertions, 10 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index a106df717..20bd20ed4 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -3,9 +3,10 @@ import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActi
3import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' 3import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { processActivities } from '../../lib/activitypub/process/process' 5import { processActivities } from '../../lib/activitypub/process/process'
6import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' 6import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'
7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
8import { ActorModel } from '../../models/activitypub/actor' 8import { VideoChannelModel } from '../../models/video/video-channel'
9import { AccountModel } from '../../models/account/account'
9 10
10const inboxRouter = express.Router() 11const inboxRouter = express.Router()
11 12
@@ -23,6 +24,13 @@ inboxRouter.post('/accounts/:name/inbox',
23 asyncMiddleware(activityPubValidator), 24 asyncMiddleware(activityPubValidator),
24 asyncMiddleware(inboxController) 25 asyncMiddleware(inboxController)
25) 26)
27inboxRouter.post('/video-channels/:name/inbox',
28 signatureValidator,
29 asyncMiddleware(checkSignature),
30 asyncMiddleware(localVideoChannelValidator),
31 asyncMiddleware(activityPubValidator),
32 asyncMiddleware(inboxController)
33)
26 34
27// --------------------------------------------------------------------------- 35// ---------------------------------------------------------------------------
28 36
@@ -49,16 +57,16 @@ async function inboxController (req: express.Request, res: express.Response, nex
49 activities = activities.filter(a => isActivityValid(a)) 57 activities = activities.filter(a => isActivityValid(a))
50 logger.debug('We keep %d activities.', activities.length, { activities }) 58 logger.debug('We keep %d activities.', activities.length, { activities })
51 59
52 let specificActor: ActorModel = undefined 60 let accountOrChannel: VideoChannelModel | AccountModel
53 if (res.locals.account) { 61 if (res.locals.account) {
54 specificActor = res.locals.account 62 accountOrChannel = res.locals.account
55 } else if (res.locals.videoChannel) { 63 } else if (res.locals.videoChannel) {
56 specificActor = res.locals.videoChannel 64 accountOrChannel = res.locals.videoChannel
57 } 65 }
58 66
59 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url) 67 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
60 68
61 await processActivities(activities, res.locals.signature.actor, specificActor) 69 await processActivities(activities, res.locals.signature.actor, accountOrChannel ? accountOrChannel.Actor : undefined)
62 70
63 res.status(204).end() 71 res.status(204).end()
64} 72}
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index ae7adcd4c..db69ae54b 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -5,11 +5,12 @@ import { activityPubCollectionPagination, activityPubContextify } from '../../he
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { announceActivityData, createActivityData } from '../../lib/activitypub/send' 6import { announceActivityData, createActivityData } from '../../lib/activitypub/send'
7import { buildAudience } from '../../lib/activitypub/audience' 7import { buildAudience } from '../../lib/activitypub/audience'
8import { asyncMiddleware, localAccountValidator } from '../../middlewares' 8import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares'
9import { AccountModel } from '../../models/account/account' 9import { AccountModel } from '../../models/account/account'
10import { ActorModel } from '../../models/activitypub/actor' 10import { ActorModel } from '../../models/activitypub/actor'
11import { VideoModel } from '../../models/video/video' 11import { VideoModel } from '../../models/video/video'
12import { activityPubResponse } from './utils' 12import { activityPubResponse } from './utils'
13import { VideoChannelModel } from '../../models/video/video-channel'
13 14
14const outboxRouter = express.Router() 15const outboxRouter = express.Router()
15 16
@@ -18,6 +19,11 @@ outboxRouter.get('/accounts/:name/outbox',
18 asyncMiddleware(outboxController) 19 asyncMiddleware(outboxController)
19) 20)
20 21
22outboxRouter.get('/video-channels/:name/outbox',
23 localVideoChannelValidator,
24 asyncMiddleware(outboxController)
25)
26
21// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
22 28
23export { 29export {
@@ -27,9 +33,9 @@ export {
27// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
28 34
29async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { 35async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) {
30 const account: AccountModel = res.locals.account 36 const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel
31 const actor = account.Actor 37 const actor = accountOrVideoChannel.Actor
32 const actorOutboxUrl = account.Actor.url + '/outbox' 38 const actorOutboxUrl = actor.url + '/outbox'
33 39
34 logger.info('Receiving outbox request for %s.', actorOutboxUrl) 40 logger.info('Receiving outbox request for %s.', actorOutboxUrl)
35 41