aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-26 10:55:40 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commit418d092afa81e2c8fe8ac6838fc4b5eb0af6a782 (patch)
tree5e9bc5604fd5d66a006cfebb7acdbdd5486e5d1e /server/controllers/activitypub
parentb427febb4d5cebf03b815bca2c59af6e82491569 (diff)
downloadPeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.tar.gz
PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.tar.zst
PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.zip
Playlist server API
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts59
-rw-r--r--server/controllers/activitypub/outbox.ts2
2 files changed, 55 insertions, 6 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 31c0a5fbd..59e6c8e9f 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -14,7 +14,7 @@ import {
14 videosCustomGetValidator, 14 videosCustomGetValidator,
15 videosShareValidator 15 videosShareValidator
16} from '../../middlewares' 16} from '../../middlewares'
17import { getAccountVideoRateValidator, videoCommentGetValidator, videosGetValidator } from '../../middlewares/validators' 17import { getAccountVideoRateValidator, videoCommentGetValidator } from '../../middlewares/validators'
18import { AccountModel } from '../../models/account/account' 18import { AccountModel } from '../../models/account/account'
19import { ActorModel } from '../../models/activitypub/actor' 19import { ActorModel } from '../../models/activitypub/actor'
20import { ActorFollowModel } from '../../models/activitypub/actor-follow' 20import { ActorFollowModel } from '../../models/activitypub/actor-follow'
@@ -37,6 +37,10 @@ import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator }
37import { getServerActor } from '../../helpers/utils' 37import { getServerActor } from '../../helpers/utils'
38import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' 38import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
39import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' 39import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
40import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists'
41import { VideoPlaylistModel } from '../../models/video/video-playlist'
42import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
43import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
40 44
41const activityPubClientRouter = express.Router() 45const activityPubClientRouter = express.Router()
42 46
@@ -52,6 +56,10 @@ activityPubClientRouter.get('/accounts?/:name/following',
52 executeIfActivityPub(asyncMiddleware(localAccountValidator)), 56 executeIfActivityPub(asyncMiddleware(localAccountValidator)),
53 executeIfActivityPub(asyncMiddleware(accountFollowingController)) 57 executeIfActivityPub(asyncMiddleware(accountFollowingController))
54) 58)
59activityPubClientRouter.get('/accounts?/:name/playlists',
60 executeIfActivityPub(asyncMiddleware(localAccountValidator)),
61 executeIfActivityPub(asyncMiddleware(accountPlaylistsController))
62)
55activityPubClientRouter.get('/accounts?/:name/likes/:videoId', 63activityPubClientRouter.get('/accounts?/:name/likes/:videoId',
56 executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))), 64 executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))),
57 executeIfActivityPub(getAccountVideoRate('like')) 65 executeIfActivityPub(getAccountVideoRate('like'))
@@ -121,6 +129,15 @@ activityPubClientRouter.get('/redundancy/video-playlists/:streamingPlaylistType/
121 executeIfActivityPub(asyncMiddleware(videoRedundancyController)) 129 executeIfActivityPub(asyncMiddleware(videoRedundancyController))
122) 130)
123 131
132activityPubClientRouter.get('/video-playlists/:playlistId',
133 executeIfActivityPub(asyncMiddleware(videoPlaylistsGetValidator)),
134 executeIfActivityPub(asyncMiddleware(videoPlaylistController))
135)
136activityPubClientRouter.get('/video-playlists/:playlistId/:videoId',
137 executeIfActivityPub(asyncMiddleware(videoPlaylistElementAPGetValidator)),
138 executeIfActivityPub(asyncMiddleware(videoPlaylistElementController))
139)
140
124// --------------------------------------------------------------------------- 141// ---------------------------------------------------------------------------
125 142
126export { 143export {
@@ -129,26 +146,33 @@ export {
129 146
130// --------------------------------------------------------------------------- 147// ---------------------------------------------------------------------------
131 148
132function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { 149function accountController (req: express.Request, res: express.Response) {
133 const account: AccountModel = res.locals.account 150 const account: AccountModel = res.locals.account
134 151
135 return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res) 152 return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res)
136} 153}
137 154
138async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { 155async function accountFollowersController (req: express.Request, res: express.Response) {
139 const account: AccountModel = res.locals.account 156 const account: AccountModel = res.locals.account
140 const activityPubResult = await actorFollowers(req, account.Actor) 157 const activityPubResult = await actorFollowers(req, account.Actor)
141 158
142 return activityPubResponse(activityPubContextify(activityPubResult), res) 159 return activityPubResponse(activityPubContextify(activityPubResult), res)
143} 160}
144 161
145async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { 162async function accountFollowingController (req: express.Request, res: express.Response) {
146 const account: AccountModel = res.locals.account 163 const account: AccountModel = res.locals.account
147 const activityPubResult = await actorFollowing(req, account.Actor) 164 const activityPubResult = await actorFollowing(req, account.Actor)
148 165
149 return activityPubResponse(activityPubContextify(activityPubResult), res) 166 return activityPubResponse(activityPubContextify(activityPubResult), res)
150} 167}
151 168
169async function accountPlaylistsController (req: express.Request, res: express.Response) {
170 const account: AccountModel = res.locals.account
171 const activityPubResult = await actorPlaylists(req, account)
172
173 return activityPubResponse(activityPubContextify(activityPubResult), res)
174}
175
152function getAccountVideoRate (rateType: VideoRateType) { 176function getAccountVideoRate (rateType: VideoRateType) {
153 return (req: express.Request, res: express.Response) => { 177 return (req: express.Request, res: express.Response) => {
154 const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate 178 const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate
@@ -293,6 +317,23 @@ async function videoRedundancyController (req: express.Request, res: express.Res
293 return activityPubResponse(activityPubContextify(object), res) 317 return activityPubResponse(activityPubContextify(object), res)
294} 318}
295 319
320async function videoPlaylistController (req: express.Request, res: express.Response) {
321 const playlist: VideoPlaylistModel = res.locals.videoPlaylist
322
323 const json = await playlist.toActivityPubObject()
324 const audience = getAudience(playlist.OwnerAccount.Actor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC)
325 const object = audiencify(json, audience)
326
327 return activityPubResponse(activityPubContextify(object), res)
328}
329
330async function videoPlaylistElementController (req: express.Request, res: express.Response) {
331 const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement
332
333 const json = videoPlaylistElement.toActivityPubObject()
334 return activityPubResponse(activityPubContextify(json), res)
335}
336
296// --------------------------------------------------------------------------- 337// ---------------------------------------------------------------------------
297 338
298async function actorFollowing (req: express.Request, actor: ActorModel) { 339async function actorFollowing (req: express.Request, actor: ActorModel) {
@@ -305,7 +346,15 @@ async function actorFollowing (req: express.Request, actor: ActorModel) {
305 346
306async function actorFollowers (req: express.Request, actor: ActorModel) { 347async function actorFollowers (req: express.Request, actor: ActorModel) {
307 const handler = (start: number, count: number) => { 348 const handler = (start: number, count: number) => {
308 return ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count) 349 return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count)
350 }
351
352 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
353}
354
355async function actorPlaylists (req: express.Request, account: AccountModel) {
356 const handler = (start: number, count: number) => {
357 return VideoPlaylistModel.listUrlsOfForAP(account.id, start, count)
309 } 358 }
310 359
311 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) 360 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index bd0e4fe9d..e060affb2 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -32,7 +32,7 @@ export {
32 32
33// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
34 34
35async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { 35async function outboxController (req: express.Request, res: express.Response) {
36 const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel 36 const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel
37 const actor = accountOrVideoChannel.Actor 37 const actor = accountOrVideoChannel.Actor
38 const actorOutboxUrl = actor.url + '/outbox' 38 const actorOutboxUrl = actor.url + '/outbox'