From 06a05d5f4784a7cbb27aa1188385b5679845dad8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Aug 2018 15:25:20 +0200 Subject: Add subscriptions endpoints to REST API --- server/controllers/activitypub/inbox.ts | 20 ++++++++++++++------ server/controllers/activitypub/outbox.ts | 14 ++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'server/controllers/activitypub') 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 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() } 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 import { logger } from '../../helpers/logger' import { announceActivityData, createActivityData } from '../../lib/activitypub/send' import { buildAudience } from '../../lib/activitypub/audience' -import { asyncMiddleware, localAccountValidator } from '../../middlewares' +import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares' import { AccountModel } from '../../models/account/account' import { ActorModel } from '../../models/activitypub/actor' import { VideoModel } from '../../models/video/video' import { activityPubResponse } from './utils' +import { VideoChannelModel } from '../../models/video/video-channel' const outboxRouter = express.Router() @@ -18,6 +19,11 @@ outboxRouter.get('/accounts/:name/outbox', asyncMiddleware(outboxController) ) +outboxRouter.get('/video-channels/:name/outbox', + localVideoChannelValidator, + asyncMiddleware(outboxController) +) + // --------------------------------------------------------------------------- export { @@ -27,9 +33,9 @@ export { // --------------------------------------------------------------------------- async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { - const account: AccountModel = res.locals.account - const actor = account.Actor - const actorOutboxUrl = account.Actor.url + '/outbox' + const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel + const actor = accountOrVideoChannel.Actor + const actorOutboxUrl = actor.url + '/outbox' logger.info('Receiving outbox request for %s.', actorOutboxUrl) -- cgit v1.2.3