diff options
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 2812bfe1e..84828e7e0 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | // Intercept ActivityPub client requests | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' | 2 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' |
4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | 3 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
@@ -37,10 +36,12 @@ import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' | |||
37 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' | 36 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' |
38 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 37 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
39 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 38 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
40 | import { MAccountId, MActorId, MVideo, MVideoAPWithoutCaption } from '@server/typings/models' | 39 | import { MAccountId, MActorId, MVideoAPWithoutCaption, MVideoId } from '@server/typings/models' |
41 | 40 | ||
42 | const activityPubClientRouter = express.Router() | 41 | const activityPubClientRouter = express.Router() |
43 | 42 | ||
43 | // Intercept ActivityPub client requests | ||
44 | |||
44 | activityPubClientRouter.get('/accounts?/:name', | 45 | activityPubClientRouter.get('/accounts?/:name', |
45 | executeIfActivityPub, | 46 | executeIfActivityPub, |
46 | asyncMiddleware(localAccountValidator), | 47 | asyncMiddleware(localAccountValidator), |
@@ -85,7 +86,7 @@ activityPubClientRouter.get('/videos/watch/:id/activity', | |||
85 | ) | 86 | ) |
86 | activityPubClientRouter.get('/videos/watch/:id/announces', | 87 | activityPubClientRouter.get('/videos/watch/:id/announces', |
87 | executeIfActivityPub, | 88 | executeIfActivityPub, |
88 | asyncMiddleware(videosCustomGetValidator('only-video')), | 89 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
89 | asyncMiddleware(videoAnnouncesController) | 90 | asyncMiddleware(videoAnnouncesController) |
90 | ) | 91 | ) |
91 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | 92 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', |
@@ -95,17 +96,17 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | |||
95 | ) | 96 | ) |
96 | activityPubClientRouter.get('/videos/watch/:id/likes', | 97 | activityPubClientRouter.get('/videos/watch/:id/likes', |
97 | executeIfActivityPub, | 98 | executeIfActivityPub, |
98 | asyncMiddleware(videosCustomGetValidator('only-video')), | 99 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
99 | asyncMiddleware(videoLikesController) | 100 | asyncMiddleware(videoLikesController) |
100 | ) | 101 | ) |
101 | activityPubClientRouter.get('/videos/watch/:id/dislikes', | 102 | activityPubClientRouter.get('/videos/watch/:id/dislikes', |
102 | executeIfActivityPub, | 103 | executeIfActivityPub, |
103 | asyncMiddleware(videosCustomGetValidator('only-video')), | 104 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
104 | asyncMiddleware(videoDislikesController) | 105 | asyncMiddleware(videoDislikesController) |
105 | ) | 106 | ) |
106 | activityPubClientRouter.get('/videos/watch/:id/comments', | 107 | activityPubClientRouter.get('/videos/watch/:id/comments', |
107 | executeIfActivityPub, | 108 | executeIfActivityPub, |
108 | asyncMiddleware(videosCustomGetValidator('only-video')), | 109 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
109 | asyncMiddleware(videoCommentsController) | 110 | asyncMiddleware(videoCommentsController) |
110 | ) | 111 | ) |
111 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', | 112 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', |
@@ -238,7 +239,7 @@ async function videoAnnounceController (req: express.Request, res: express.Respo | |||
238 | } | 239 | } |
239 | 240 | ||
240 | async function videoAnnouncesController (req: express.Request, res: express.Response) { | 241 | async function videoAnnouncesController (req: express.Request, res: express.Response) { |
241 | const video = res.locals.onlyVideo | 242 | const video = res.locals.onlyImmutableVideo |
242 | 243 | ||
243 | const handler = async (start: number, count: number) => { | 244 | const handler = async (start: number, count: number) => { |
244 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) | 245 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) |
@@ -253,21 +254,21 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp | |||
253 | } | 254 | } |
254 | 255 | ||
255 | async function videoLikesController (req: express.Request, res: express.Response) { | 256 | async function videoLikesController (req: express.Request, res: express.Response) { |
256 | const video = res.locals.onlyVideo | 257 | const video = res.locals.onlyImmutableVideo |
257 | const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) | 258 | const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) |
258 | 259 | ||
259 | return activityPubResponse(activityPubContextify(json), res) | 260 | return activityPubResponse(activityPubContextify(json), res) |
260 | } | 261 | } |
261 | 262 | ||
262 | async function videoDislikesController (req: express.Request, res: express.Response) { | 263 | async function videoDislikesController (req: express.Request, res: express.Response) { |
263 | const video = res.locals.onlyVideo | 264 | const video = res.locals.onlyImmutableVideo |
264 | const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) | 265 | const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) |
265 | 266 | ||
266 | return activityPubResponse(activityPubContextify(json), res) | 267 | return activityPubResponse(activityPubContextify(json), res) |
267 | } | 268 | } |
268 | 269 | ||
269 | async function videoCommentsController (req: express.Request, res: express.Response) { | 270 | async function videoCommentsController (req: express.Request, res: express.Response) { |
270 | const video = res.locals.onlyVideo | 271 | const video = res.locals.onlyImmutableVideo |
271 | 272 | ||
272 | const handler = async (start: number, count: number) => { | 273 | const handler = async (start: number, count: number) => { |
273 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) | 274 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) |
@@ -334,10 +335,10 @@ async function videoRedundancyController (req: express.Request, res: express.Res | |||
334 | 335 | ||
335 | if (req.path.endsWith('/activity')) { | 336 | if (req.path.endsWith('/activity')) { |
336 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) | 337 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) |
337 | return activityPubResponse(activityPubContextify(data), res) | 338 | return activityPubResponse(activityPubContextify(data, 'CacheFile'), res) |
338 | } | 339 | } |
339 | 340 | ||
340 | return activityPubResponse(activityPubContextify(object), res) | 341 | return activityPubResponse(activityPubContextify(object, 'CacheFile'), res) |
341 | } | 342 | } |
342 | 343 | ||
343 | async function videoPlaylistController (req: express.Request, res: express.Response) { | 344 | async function videoPlaylistController (req: express.Request, res: express.Response) { |
@@ -386,7 +387,7 @@ async function actorPlaylists (req: express.Request, account: MAccountId) { | |||
386 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) | 387 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
387 | } | 388 | } |
388 | 389 | ||
389 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideo, url: string) { | 390 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideoId, url: string) { |
390 | const handler = async (start: number, count: number) => { | 391 | const handler = async (start: number, count: number) => { |
391 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) | 392 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) |
392 | return { | 393 | return { |