aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-27 14:44:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch)
treee1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/controllers
parent74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff)
downloadPeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.gz
PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.zst
PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.zip
Add shares forward and collection on videos/video channels
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/client.ts48
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
2import * as express from 'express' 2import * as express from 'express'
3
4import { database as db } from '../../initializers'
5import { executeIfActivityPub, localAccountValidator } from '../../middlewares'
6import { pageToStartAndCount } from '../../helpers' 3import { pageToStartAndCount } from '../../helpers'
7import { AccountInstance, VideoChannelInstance } from '../../models'
8import { activityPubCollectionPagination } from '../../helpers/activitypub' 4import { activityPubCollectionPagination } from '../../helpers/activitypub'
5
6import { database as db } from '../../initializers'
9import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' 7import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants'
8import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send/send-announce'
9import { buildVideoAnnounceToFollowers } from '../../lib/index'
10import { executeIfActivityPub, localAccountValidator } from '../../middlewares'
10import { asyncMiddleware } from '../../middlewares/async' 11import { asyncMiddleware } from '../../middlewares/async'
11import { videosGetValidator } from '../../middlewares/validators/videos' 12import { videoChannelsGetValidator, videoChannelsShareValidator } from '../../middlewares/validators/video-channels'
13import { videosGetValidator, videosShareValidator } from '../../middlewares/validators/videos'
14import { AccountInstance, VideoChannelInstance } from '../../models'
15import { VideoChannelShareInstance } from '../../models/video/video-channel-share-interface'
12import { VideoInstance } from '../../models/video/video-interface' 16import { VideoInstance } from '../../models/video/video-interface'
13import { videoChannelsGetValidator } from '../../middlewares/validators/video-channels' 17import { VideoShareInstance } from '../../models/video/video-share-interface'
14 18
15const activityPubClientRouter = express.Router() 19const activityPubClientRouter = express.Router()
16 20
17activityPubClientRouter.get('/account/:name', 21activityPubClientRouter.get('/account/:name',
18 executeIfActivityPub(localAccountValidator), 22 executeIfActivityPub(localAccountValidator),
19 executeIfActivityPub(asyncMiddleware(accountController)) 23 executeIfActivityPub(accountController)
20) 24)
21 25
22activityPubClientRouter.get('/account/:name/followers', 26activityPubClientRouter.get('/account/:name/followers',
@@ -31,7 +35,12 @@ activityPubClientRouter.get('/account/:name/following',
31 35
32activityPubClientRouter.get('/videos/watch/:id', 36activityPubClientRouter.get('/videos/watch/:id',
33 executeIfActivityPub(videosGetValidator), 37 executeIfActivityPub(videosGetValidator),
34 executeIfActivityPub(asyncMiddleware(videoController)) 38 executeIfActivityPub(videoController)
39)
40
41activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
42 executeIfActivityPub(asyncMiddleware(videosShareValidator)),
43 executeIfActivityPub(asyncMiddleware(videoAnnounceController))
35) 44)
36 45
37activityPubClientRouter.get('/video-channels/:id', 46activityPubClientRouter.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
51activityPubClientRouter.get('/video-channels/:id/announces/:accountId',
52 executeIfActivityPub(asyncMiddleware(videoChannelsShareValidator)),
53 executeIfActivityPub(asyncMiddleware(videoChannelAnnounceController))
54)
55
42// --------------------------------------------------------------------------- 56// ---------------------------------------------------------------------------
43 57
44export { 58export {
@@ -47,7 +61,7 @@ export {
47 61
48// --------------------------------------------------------------------------- 62// ---------------------------------------------------------------------------
49 63
50async function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { 64function 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
80async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { 94function 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
100async 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
107async 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
86async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { 114async 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