diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-16 15:25:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-27 09:41:54 +0200 |
commit | 06a05d5f4784a7cbb27aa1188385b5679845dad8 (patch) | |
tree | ac197f3ed0768529456225ad76c912f22bc55e29 /server/controllers/activitypub | |
parent | 4bda2e47bbc937c401ddcf14c1be53c70481a294 (diff) | |
download | PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.gz PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.zst PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.zip |
Add subscriptions endpoints to REST API
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 20 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 14 |
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 | |||
3 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' | 3 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { processActivities } from '../../lib/activitypub/process/process' | 5 | import { processActivities } from '../../lib/activitypub/process/process' |
6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' | 6 | import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' |
7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
8 | import { ActorModel } from '../../models/activitypub/actor' | 8 | import { VideoChannelModel } from '../../models/video/video-channel' |
9 | import { AccountModel } from '../../models/account/account' | ||
9 | 10 | ||
10 | const inboxRouter = express.Router() | 11 | const 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 | ) |
27 | inboxRouter.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 | |||
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' | 6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' |
7 | import { buildAudience } from '../../lib/activitypub/audience' | 7 | import { buildAudience } from '../../lib/activitypub/audience' |
8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 8 | import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares' |
9 | import { AccountModel } from '../../models/account/account' | 9 | import { AccountModel } from '../../models/account/account' |
10 | import { ActorModel } from '../../models/activitypub/actor' | 10 | import { ActorModel } from '../../models/activitypub/actor' |
11 | import { VideoModel } from '../../models/video/video' | 11 | import { VideoModel } from '../../models/video/video' |
12 | import { activityPubResponse } from './utils' | 12 | import { activityPubResponse } from './utils' |
13 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
13 | 14 | ||
14 | const outboxRouter = express.Router() | 15 | const outboxRouter = express.Router() |
15 | 16 | ||
@@ -18,6 +19,11 @@ outboxRouter.get('/accounts/:name/outbox', | |||
18 | asyncMiddleware(outboxController) | 19 | asyncMiddleware(outboxController) |
19 | ) | 20 | ) |
20 | 21 | ||
22 | outboxRouter.get('/video-channels/:name/outbox', | ||
23 | localVideoChannelValidator, | ||
24 | asyncMiddleware(outboxController) | ||
25 | ) | ||
26 | |||
21 | // --------------------------------------------------------------------------- | 27 | // --------------------------------------------------------------------------- |
22 | 28 | ||
23 | export { | 29 | export { |
@@ -27,9 +33,9 @@ export { | |||
27 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |
28 | 34 | ||
29 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 35 | async 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 | ||