diff options
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 59 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 2 |
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' |
17 | import { getAccountVideoRateValidator, videoCommentGetValidator, videosGetValidator } from '../../middlewares/validators' | 17 | import { getAccountVideoRateValidator, videoCommentGetValidator } from '../../middlewares/validators' |
18 | import { AccountModel } from '../../models/account/account' | 18 | import { AccountModel } from '../../models/account/account' |
19 | import { ActorModel } from '../../models/activitypub/actor' | 19 | import { ActorModel } from '../../models/activitypub/actor' |
20 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 20 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
@@ -37,6 +37,10 @@ import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } | |||
37 | import { getServerActor } from '../../helpers/utils' | 37 | import { getServerActor } from '../../helpers/utils' |
38 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | 38 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' |
39 | import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' | 39 | import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' |
40 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' | ||
41 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | ||
42 | import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' | ||
43 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | ||
40 | 44 | ||
41 | const activityPubClientRouter = express.Router() | 45 | const 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 | ) |
59 | activityPubClientRouter.get('/accounts?/:name/playlists', | ||
60 | executeIfActivityPub(asyncMiddleware(localAccountValidator)), | ||
61 | executeIfActivityPub(asyncMiddleware(accountPlaylistsController)) | ||
62 | ) | ||
55 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', | 63 | activityPubClientRouter.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 | ||
132 | activityPubClientRouter.get('/video-playlists/:playlistId', | ||
133 | executeIfActivityPub(asyncMiddleware(videoPlaylistsGetValidator)), | ||
134 | executeIfActivityPub(asyncMiddleware(videoPlaylistController)) | ||
135 | ) | ||
136 | activityPubClientRouter.get('/video-playlists/:playlistId/:videoId', | ||
137 | executeIfActivityPub(asyncMiddleware(videoPlaylistElementAPGetValidator)), | ||
138 | executeIfActivityPub(asyncMiddleware(videoPlaylistElementController)) | ||
139 | ) | ||
140 | |||
124 | // --------------------------------------------------------------------------- | 141 | // --------------------------------------------------------------------------- |
125 | 142 | ||
126 | export { | 143 | export { |
@@ -129,26 +146,33 @@ export { | |||
129 | 146 | ||
130 | // --------------------------------------------------------------------------- | 147 | // --------------------------------------------------------------------------- |
131 | 148 | ||
132 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { | 149 | function 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 | ||
138 | async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { | 155 | async 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 | ||
145 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { | 162 | async 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 | ||
169 | async 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 | |||
152 | function getAccountVideoRate (rateType: VideoRateType) { | 176 | function 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 | ||
320 | async 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 | |||
330 | async 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 | ||
298 | async function actorFollowing (req: express.Request, actor: ActorModel) { | 339 | async function actorFollowing (req: express.Request, actor: ActorModel) { |
@@ -305,7 +346,15 @@ async function actorFollowing (req: express.Request, actor: ActorModel) { | |||
305 | 346 | ||
306 | async function actorFollowers (req: express.Request, actor: ActorModel) { | 347 | async 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 | |||
355 | async 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 | ||
35 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 35 | async 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' |