diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 14:44:51 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch) | |
tree | e1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/controllers/activitypub | |
parent | 74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff) | |
download | PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.gz PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.zst PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.zip |
Add shares forward and collection on videos/video channels
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index eee89e2fd..41272bca0 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,22 +1,26 @@ | |||
1 | // Intercept ActivityPub client requests | 1 | // Intercept ActivityPub client requests |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | |||
4 | import { database as db } from '../../initializers' | ||
5 | import { executeIfActivityPub, localAccountValidator } from '../../middlewares' | ||
6 | import { pageToStartAndCount } from '../../helpers' | 3 | import { pageToStartAndCount } from '../../helpers' |
7 | import { AccountInstance, VideoChannelInstance } from '../../models' | ||
8 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 4 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
5 | |||
6 | import { database as db } from '../../initializers' | ||
9 | import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' | 7 | import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' |
8 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send/send-announce' | ||
9 | import { buildVideoAnnounceToFollowers } from '../../lib/index' | ||
10 | import { executeIfActivityPub, localAccountValidator } from '../../middlewares' | ||
10 | import { asyncMiddleware } from '../../middlewares/async' | 11 | import { asyncMiddleware } from '../../middlewares/async' |
11 | import { videosGetValidator } from '../../middlewares/validators/videos' | 12 | import { videoChannelsGetValidator, videoChannelsShareValidator } from '../../middlewares/validators/video-channels' |
13 | import { videosGetValidator, videosShareValidator } from '../../middlewares/validators/videos' | ||
14 | import { AccountInstance, VideoChannelInstance } from '../../models' | ||
15 | import { VideoChannelShareInstance } from '../../models/video/video-channel-share-interface' | ||
12 | import { VideoInstance } from '../../models/video/video-interface' | 16 | import { VideoInstance } from '../../models/video/video-interface' |
13 | import { videoChannelsGetValidator } from '../../middlewares/validators/video-channels' | 17 | import { VideoShareInstance } from '../../models/video/video-share-interface' |
14 | 18 | ||
15 | const activityPubClientRouter = express.Router() | 19 | const activityPubClientRouter = express.Router() |
16 | 20 | ||
17 | activityPubClientRouter.get('/account/:name', | 21 | activityPubClientRouter.get('/account/:name', |
18 | executeIfActivityPub(localAccountValidator), | 22 | executeIfActivityPub(localAccountValidator), |
19 | executeIfActivityPub(asyncMiddleware(accountController)) | 23 | executeIfActivityPub(accountController) |
20 | ) | 24 | ) |
21 | 25 | ||
22 | activityPubClientRouter.get('/account/:name/followers', | 26 | activityPubClientRouter.get('/account/:name/followers', |
@@ -31,7 +35,12 @@ activityPubClientRouter.get('/account/:name/following', | |||
31 | 35 | ||
32 | activityPubClientRouter.get('/videos/watch/:id', | 36 | activityPubClientRouter.get('/videos/watch/:id', |
33 | executeIfActivityPub(videosGetValidator), | 37 | executeIfActivityPub(videosGetValidator), |
34 | executeIfActivityPub(asyncMiddleware(videoController)) | 38 | executeIfActivityPub(videoController) |
39 | ) | ||
40 | |||
41 | activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', | ||
42 | executeIfActivityPub(asyncMiddleware(videosShareValidator)), | ||
43 | executeIfActivityPub(asyncMiddleware(videoAnnounceController)) | ||
35 | ) | 44 | ) |
36 | 45 | ||
37 | activityPubClientRouter.get('/video-channels/:id', | 46 | activityPubClientRouter.get('/video-channels/:id', |
@@ -39,6 +48,11 @@ activityPubClientRouter.get('/video-channels/:id', | |||
39 | executeIfActivityPub(asyncMiddleware(videoChannelController)) | 48 | executeIfActivityPub(asyncMiddleware(videoChannelController)) |
40 | ) | 49 | ) |
41 | 50 | ||
51 | activityPubClientRouter.get('/video-channels/:id/announces/:accountId', | ||
52 | executeIfActivityPub(asyncMiddleware(videoChannelsShareValidator)), | ||
53 | executeIfActivityPub(asyncMiddleware(videoChannelAnnounceController)) | ||
54 | ) | ||
55 | |||
42 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
43 | 57 | ||
44 | export { | 58 | export { |
@@ -47,7 +61,7 @@ export { | |||
47 | 61 | ||
48 | // --------------------------------------------------------------------------- | 62 | // --------------------------------------------------------------------------- |
49 | 63 | ||
50 | async function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { | 64 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { |
51 | const account: AccountInstance = res.locals.account | 65 | const account: AccountInstance = res.locals.account |
52 | 66 | ||
53 | return res.json(account.toActivityPubObject()).end() | 67 | return res.json(account.toActivityPubObject()).end() |
@@ -77,12 +91,26 @@ async function accountFollowingController (req: express.Request, res: express.Re | |||
77 | return res.json(activityPubResult) | 91 | return res.json(activityPubResult) |
78 | } | 92 | } |
79 | 93 | ||
80 | async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { | 94 | function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { |
81 | const video: VideoInstance = res.locals.video | 95 | const video: VideoInstance = res.locals.video |
82 | 96 | ||
83 | return res.json(video.toActivityPubObject()) | 97 | return res.json(video.toActivityPubObject()) |
84 | } | 98 | } |
85 | 99 | ||
100 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
101 | const share = res.locals.videoShare as VideoShareInstance | ||
102 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) | ||
103 | |||
104 | return res.json(object) | ||
105 | } | ||
106 | |||
107 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
108 | const share = res.locals.videoChannelShare as VideoChannelShareInstance | ||
109 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) | ||
110 | |||
111 | return res.json(object) | ||
112 | } | ||
113 | |||
86 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { | 114 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { |
87 | const videoChannel: VideoChannelInstance = res.locals.videoChannel | 115 | const videoChannel: VideoChannelInstance = res.locals.videoChannel |
88 | 116 | ||