]>
Commit | Line | Data |
---|---|---|
41fb13c3 C |
1 | import cors from 'cors' |
2 | import express from 'express' | |
053aed43 | 3 | import { getServerActor } from '@server/models/application/application' |
55d5fbc5 | 4 | import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models' |
8fffe21a | 5 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' |
053aed43 | 6 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
d6e99e53 | 7 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
74dc3bca | 8 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants' |
e251f170 | 9 | import { audiencify, getAudience } from '../../lib/activitypub/audience' |
053aed43 | 10 | import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send' |
c48e82b5 | 11 | import { buildCreateActivity } from '../../lib/activitypub/send/send-create' |
053aed43 C |
12 | import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' |
13 | import { | |
de94ac86 C |
14 | getLocalVideoCommentsActivityPubUrl, |
15 | getLocalVideoDislikesActivityPubUrl, | |
16 | getLocalVideoLikesActivityPubUrl, | |
17 | getLocalVideoSharesActivityPubUrl | |
053aed43 | 18 | } from '../../lib/activitypub/url' |
96f29c0f C |
19 | import { |
20 | asyncMiddleware, | |
21 | executeIfActivityPub, | |
22 | localAccountValidator, | |
a37e9e74 | 23 | videoChannelsNameWithHostValidator, |
24 | ensureIsLocalChannel, | |
1e7eb25f C |
25 | videosCustomGetValidator, |
26 | videosShareValidator | |
96f29c0f | 27 | } from '../../middlewares' |
20bafcb6 | 28 | import { cacheRoute } from '../../middlewares/cache/cache' |
75ba887d | 29 | import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators' |
053aed43 C |
30 | import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' |
31 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' | |
3fd3ab2d | 32 | import { AccountModel } from '../../models/account/account' |
053aed43 | 33 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
7d9ba5c0 | 34 | import { ActorFollowModel } from '../../models/actor/actor-follow' |
053aed43 | 35 | import { VideoCaptionModel } from '../../models/video/video-caption' |
da854ddd | 36 | import { VideoCommentModel } from '../../models/video/video-comment' |
053aed43 | 37 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
3fd3ab2d | 38 | import { VideoShareModel } from '../../models/video/video-share' |
8fffe21a | 39 | import { activityPubResponse } from './utils' |
e4f97bab C |
40 | |
41 | const activityPubClientRouter = express.Router() | |
670e955c | 42 | activityPubClientRouter.use(cors()) |
e4f97bab | 43 | |
2c8776fc C |
44 | // Intercept ActivityPub client requests |
45 | ||
70fdff3d | 46 | activityPubClientRouter.get( |
559985b5 | 47 | [ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ], |
e65c0c5b C |
48 | executeIfActivityPub, |
49 | asyncMiddleware(localAccountValidator), | |
50 | accountController | |
e4f97bab | 51 | ) |
7006bc63 | 52 | activityPubClientRouter.get('/accounts?/:name/followers', |
e65c0c5b C |
53 | executeIfActivityPub, |
54 | asyncMiddleware(localAccountValidator), | |
55 | asyncMiddleware(accountFollowersController) | |
e4f97bab | 56 | ) |
7006bc63 | 57 | activityPubClientRouter.get('/accounts?/:name/following', |
e65c0c5b C |
58 | executeIfActivityPub, |
59 | asyncMiddleware(localAccountValidator), | |
60 | asyncMiddleware(accountFollowingController) | |
e4f97bab | 61 | ) |
418d092a | 62 | activityPubClientRouter.get('/accounts?/:name/playlists', |
e65c0c5b C |
63 | executeIfActivityPub, |
64 | asyncMiddleware(localAccountValidator), | |
65 | asyncMiddleware(accountPlaylistsController) | |
418d092a | 66 | ) |
5c6d985f | 67 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', |
e65c0c5b | 68 | executeIfActivityPub, |
75ba887d C |
69 | asyncMiddleware(getAccountVideoRateValidatorFactory('like')), |
70 | getAccountVideoRateFactory('like') | |
5c6d985f C |
71 | ) |
72 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | |
e65c0c5b | 73 | executeIfActivityPub, |
75ba887d C |
74 | asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), |
75 | getAccountVideoRateFactory('dislike') | |
5c6d985f | 76 | ) |
e4f97bab | 77 | |
559985b5 C |
78 | activityPubClientRouter.get( |
79 | [ '/videos/watch/:id', '/w/:id' ], | |
e65c0c5b | 80 | executeIfActivityPub, |
20bafcb6 | 81 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
71d4af1e | 82 | asyncMiddleware(videosCustomGetValidator('all')), |
e65c0c5b | 83 | asyncMiddleware(videoController) |
4e50b6a1 | 84 | ) |
296c0905 | 85 | activityPubClientRouter.get('/videos/watch/:id/activity', |
e65c0c5b | 86 | executeIfActivityPub, |
71d4af1e | 87 | asyncMiddleware(videosCustomGetValidator('all')), |
e65c0c5b | 88 | asyncMiddleware(videoController) |
296c0905 | 89 | ) |
46531a0a | 90 | activityPubClientRouter.get('/videos/watch/:id/announces', |
e65c0c5b | 91 | executeIfActivityPub, |
7eba5e1f | 92 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
e65c0c5b | 93 | asyncMiddleware(videoAnnouncesController) |
46531a0a | 94 | ) |
5c6d985f | 95 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', |
e65c0c5b C |
96 | executeIfActivityPub, |
97 | asyncMiddleware(videosShareValidator), | |
98 | asyncMiddleware(videoAnnounceController) | |
20494f12 | 99 | ) |
46531a0a | 100 | activityPubClientRouter.get('/videos/watch/:id/likes', |
e65c0c5b | 101 | executeIfActivityPub, |
7eba5e1f | 102 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
e65c0c5b | 103 | asyncMiddleware(videoLikesController) |
46531a0a C |
104 | ) |
105 | activityPubClientRouter.get('/videos/watch/:id/dislikes', | |
e65c0c5b | 106 | executeIfActivityPub, |
7eba5e1f | 107 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
e65c0c5b | 108 | asyncMiddleware(videoDislikesController) |
46531a0a C |
109 | ) |
110 | activityPubClientRouter.get('/videos/watch/:id/comments', | |
e65c0c5b | 111 | executeIfActivityPub, |
7eba5e1f | 112 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
e65c0c5b | 113 | asyncMiddleware(videoCommentsController) |
46531a0a | 114 | ) |
da854ddd | 115 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', |
e65c0c5b C |
116 | executeIfActivityPub, |
117 | asyncMiddleware(videoCommentGetValidator), | |
118 | asyncMiddleware(videoCommentController) | |
da854ddd | 119 | ) |
296c0905 | 120 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity', |
e65c0c5b C |
121 | executeIfActivityPub, |
122 | asyncMiddleware(videoCommentGetValidator), | |
123 | asyncMiddleware(videoCommentController) | |
296c0905 | 124 | ) |
da854ddd | 125 | |
70fdff3d | 126 | activityPubClientRouter.get( |
a37e9e74 | 127 | [ '/video-channels/:nameWithHost', '/video-channels/:nameWithHost/videos', '/c/:nameWithHost', '/c/:nameWithHost/videos' ], |
e65c0c5b | 128 | executeIfActivityPub, |
a37e9e74 | 129 | asyncMiddleware(videoChannelsNameWithHostValidator), |
130 | ensureIsLocalChannel, | |
a1587156 | 131 | videoChannelController |
20494f12 | 132 | ) |
a37e9e74 | 133 | activityPubClientRouter.get('/video-channels/:nameWithHost/followers', |
e65c0c5b | 134 | executeIfActivityPub, |
a37e9e74 | 135 | asyncMiddleware(videoChannelsNameWithHostValidator), |
136 | ensureIsLocalChannel, | |
e65c0c5b | 137 | asyncMiddleware(videoChannelFollowersController) |
7006bc63 | 138 | ) |
a37e9e74 | 139 | activityPubClientRouter.get('/video-channels/:nameWithHost/following', |
e65c0c5b | 140 | executeIfActivityPub, |
a37e9e74 | 141 | asyncMiddleware(videoChannelsNameWithHostValidator), |
142 | ensureIsLocalChannel, | |
e65c0c5b | 143 | asyncMiddleware(videoChannelFollowingController) |
7006bc63 | 144 | ) |
a37e9e74 | 145 | activityPubClientRouter.get('/video-channels/:nameWithHost/playlists', |
7405b6ba | 146 | executeIfActivityPub, |
a37e9e74 | 147 | asyncMiddleware(videoChannelsNameWithHostValidator), |
148 | ensureIsLocalChannel, | |
7405b6ba C |
149 | asyncMiddleware(videoChannelPlaylistsController) |
150 | ) | |
20494f12 | 151 | |
c48e82b5 | 152 | activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?', |
e65c0c5b C |
153 | executeIfActivityPub, |
154 | asyncMiddleware(videoFileRedundancyGetValidator), | |
155 | asyncMiddleware(videoRedundancyController) | |
09209296 | 156 | ) |
9c6ca37f | 157 | activityPubClientRouter.get('/redundancy/streaming-playlists/:streamingPlaylistType/:videoId', |
e65c0c5b C |
158 | executeIfActivityPub, |
159 | asyncMiddleware(videoPlaylistRedundancyGetValidator), | |
160 | asyncMiddleware(videoRedundancyController) | |
c48e82b5 C |
161 | ) |
162 | ||
37a44fc9 C |
163 | activityPubClientRouter.get( |
164 | [ '/video-playlists/:playlistId', '/videos/watch/playlist/:playlistId', '/w/p/:playlistId' ], | |
e65c0c5b | 165 | executeIfActivityPub, |
453e83ea | 166 | asyncMiddleware(videoPlaylistsGetValidator('all')), |
e65c0c5b | 167 | asyncMiddleware(videoPlaylistController) |
418d092a | 168 | ) |
37190663 | 169 | activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId', |
e65c0c5b C |
170 | executeIfActivityPub, |
171 | asyncMiddleware(videoPlaylistElementAPGetValidator), | |
a1587156 | 172 | videoPlaylistElementController |
418d092a C |
173 | ) |
174 | ||
e4f97bab C |
175 | // --------------------------------------------------------------------------- |
176 | ||
177 | export { | |
178 | activityPubClientRouter | |
179 | } | |
180 | ||
181 | // --------------------------------------------------------------------------- | |
182 | ||
418d092a | 183 | function accountController (req: express.Request, res: express.Response) { |
dae86118 | 184 | const account = res.locals.account |
e4f97bab | 185 | |
4b8f09fa | 186 | return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res) |
e4f97bab C |
187 | } |
188 | ||
418d092a | 189 | async function accountFollowersController (req: express.Request, res: express.Response) { |
dae86118 | 190 | const account = res.locals.account |
7006bc63 | 191 | const activityPubResult = await actorFollowers(req, account.Actor) |
e4f97bab | 192 | |
4b8f09fa | 193 | return activityPubResponse(activityPubContextify(activityPubResult), res) |
e4f97bab C |
194 | } |
195 | ||
418d092a | 196 | async function accountFollowingController (req: express.Request, res: express.Response) { |
dae86118 | 197 | const account = res.locals.account |
7006bc63 | 198 | const activityPubResult = await actorFollowing(req, account.Actor) |
e4f97bab | 199 | |
4b8f09fa | 200 | return activityPubResponse(activityPubContextify(activityPubResult), res) |
e4f97bab | 201 | } |
20494f12 | 202 | |
418d092a | 203 | async function accountPlaylistsController (req: express.Request, res: express.Response) { |
dae86118 | 204 | const account = res.locals.account |
7405b6ba C |
205 | const activityPubResult = await actorPlaylists(req, { account }) |
206 | ||
207 | return activityPubResponse(activityPubContextify(activityPubResult), res) | |
208 | } | |
209 | ||
210 | async function videoChannelPlaylistsController (req: express.Request, res: express.Response) { | |
211 | const channel = res.locals.videoChannel | |
212 | const activityPubResult = await actorPlaylists(req, { channel }) | |
418d092a C |
213 | |
214 | return activityPubResponse(activityPubContextify(activityPubResult), res) | |
215 | } | |
216 | ||
75ba887d | 217 | function getAccountVideoRateFactory (rateType: VideoRateType) { |
5c6d985f | 218 | return (req: express.Request, res: express.Response) => { |
dae86118 | 219 | const accountVideoRate = res.locals.accountVideoRate |
5c6d985f C |
220 | |
221 | const byActor = accountVideoRate.Account.Actor | |
5c6d985f | 222 | const APObject = rateType === 'like' |
de94ac86 C |
223 | ? buildLikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video) |
224 | : buildDislikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video) | |
5c6d985f C |
225 | |
226 | return activityPubResponse(activityPubContextify(APObject), res) | |
227 | } | |
228 | } | |
229 | ||
1a8dd4da | 230 | async function videoController (req: express.Request, res: express.Response) { |
71d4af1e | 231 | const video = res.locals.videoAll |
20494f12 | 232 | |
de94ac86 | 233 | if (redirectIfNotOwned(video.url, res)) return |
8d1fa36a | 234 | |
40e87e9e | 235 | // We need captions to render AP object |
453e83ea | 236 | const captions = await VideoCaptionModel.listVideoCaptions(video.id) |
b5fecbf4 | 237 | const videoWithCaptions = Object.assign(video, { VideoCaptions: captions }) |
40e87e9e | 238 | |
453e83ea C |
239 | const audience = getAudience(videoWithCaptions.VideoChannel.Account.Actor, videoWithCaptions.privacy === VideoPrivacy.PUBLIC) |
240 | const videoObject = audiencify(videoWithCaptions.toActivityPubObject(), audience) | |
2ccaeeb3 | 241 | |
296c0905 | 242 | if (req.path.endsWith('/activity')) { |
453e83ea | 243 | const data = buildCreateActivity(videoWithCaptions.url, video.VideoChannel.Account.Actor, videoObject, audience) |
4b8f09fa | 244 | return activityPubResponse(activityPubContextify(data), res) |
296c0905 C |
245 | } |
246 | ||
4b8f09fa | 247 | return activityPubResponse(activityPubContextify(videoObject), res) |
20494f12 C |
248 | } |
249 | ||
1a8dd4da | 250 | async function videoAnnounceController (req: express.Request, res: express.Response) { |
dae86118 | 251 | const share = res.locals.videoShare |
8d1fa36a | 252 | |
de94ac86 | 253 | if (redirectIfNotOwned(share.url, res)) return |
8d1fa36a | 254 | |
453e83ea | 255 | const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll, undefined) |
4e50b6a1 | 256 | |
598edb8a | 257 | return activityPubResponse(activityPubContextify(activity, 'Announce'), res) |
4e50b6a1 C |
258 | } |
259 | ||
1a8dd4da | 260 | async function videoAnnouncesController (req: express.Request, res: express.Response) { |
7eba5e1f | 261 | const video = res.locals.onlyImmutableVideo |
46531a0a | 262 | |
de94ac86 C |
263 | if (redirectIfNotOwned(video.url, res)) return |
264 | ||
8fffe21a C |
265 | const handler = async (start: number, count: number) => { |
266 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) | |
267 | return { | |
268 | total: result.count, | |
269 | data: result.rows.map(r => r.url) | |
270 | } | |
271 | } | |
de94ac86 | 272 | const json = await activityPubCollectionPagination(getLocalVideoSharesActivityPubUrl(video), handler, req.query.page) |
46531a0a | 273 | |
8fffe21a | 274 | return activityPubResponse(activityPubContextify(json), res) |
46531a0a C |
275 | } |
276 | ||
1a8dd4da | 277 | async function videoLikesController (req: express.Request, res: express.Response) { |
7eba5e1f | 278 | const video = res.locals.onlyImmutableVideo |
de94ac86 C |
279 | |
280 | if (redirectIfNotOwned(video.url, res)) return | |
281 | ||
282 | const json = await videoRates(req, 'like', video, getLocalVideoLikesActivityPubUrl(video)) | |
46531a0a | 283 | |
8fffe21a | 284 | return activityPubResponse(activityPubContextify(json), res) |
46531a0a C |
285 | } |
286 | ||
1a8dd4da | 287 | async function videoDislikesController (req: express.Request, res: express.Response) { |
7eba5e1f | 288 | const video = res.locals.onlyImmutableVideo |
de94ac86 C |
289 | |
290 | if (redirectIfNotOwned(video.url, res)) return | |
291 | ||
292 | const json = await videoRates(req, 'dislike', video, getLocalVideoDislikesActivityPubUrl(video)) | |
46531a0a | 293 | |
8fffe21a | 294 | return activityPubResponse(activityPubContextify(json), res) |
46531a0a C |
295 | } |
296 | ||
1a8dd4da | 297 | async function videoCommentsController (req: express.Request, res: express.Response) { |
7eba5e1f | 298 | const video = res.locals.onlyImmutableVideo |
46531a0a | 299 | |
de94ac86 C |
300 | if (redirectIfNotOwned(video.url, res)) return |
301 | ||
8fffe21a | 302 | const handler = async (start: number, count: number) => { |
696d83fd | 303 | const result = await VideoCommentModel.listAndCountByVideoForAP(video, start, count) |
8fffe21a C |
304 | return { |
305 | total: result.count, | |
306 | data: result.rows.map(r => r.url) | |
307 | } | |
308 | } | |
de94ac86 | 309 | const json = await activityPubCollectionPagination(getLocalVideoCommentsActivityPubUrl(video), handler, req.query.page) |
46531a0a | 310 | |
8fffe21a | 311 | return activityPubResponse(activityPubContextify(json), res) |
46531a0a C |
312 | } |
313 | ||
a1587156 | 314 | function videoChannelController (req: express.Request, res: express.Response) { |
dae86118 | 315 | const videoChannel = res.locals.videoChannel |
20494f12 | 316 | |
4b8f09fa | 317 | return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) |
20494f12 | 318 | } |
da854ddd | 319 | |
1a8dd4da | 320 | async function videoChannelFollowersController (req: express.Request, res: express.Response) { |
dae86118 | 321 | const videoChannel = res.locals.videoChannel |
7006bc63 C |
322 | const activityPubResult = await actorFollowers(req, videoChannel.Actor) |
323 | ||
4b8f09fa | 324 | return activityPubResponse(activityPubContextify(activityPubResult), res) |
7006bc63 C |
325 | } |
326 | ||
1a8dd4da | 327 | async function videoChannelFollowingController (req: express.Request, res: express.Response) { |
dae86118 | 328 | const videoChannel = res.locals.videoChannel |
7006bc63 C |
329 | const activityPubResult = await actorFollowing(req, videoChannel.Actor) |
330 | ||
4b8f09fa | 331 | return activityPubResponse(activityPubContextify(activityPubResult), res) |
7006bc63 C |
332 | } |
333 | ||
1a8dd4da | 334 | async function videoCommentController (req: express.Request, res: express.Response) { |
453e83ea | 335 | const videoComment = res.locals.videoCommentFull |
da854ddd | 336 | |
de94ac86 | 337 | if (redirectIfNotOwned(videoComment.url, res)) return |
8d1fa36a | 338 | |
d7e70384 | 339 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) |
d6e99e53 | 340 | const isPublic = true // Comments are always public |
69222afa | 341 | let videoCommentObject = videoComment.toActivityPubObject(threadParentComments) |
d6e99e53 | 342 | |
69222afa JM |
343 | if (videoComment.Account) { |
344 | const audience = getAudience(videoComment.Account.Actor, isPublic) | |
345 | videoCommentObject = audiencify(videoCommentObject, audience) | |
d6e99e53 | 346 | |
69222afa JM |
347 | if (req.path.endsWith('/activity')) { |
348 | const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) | |
349 | return activityPubResponse(activityPubContextify(data), res) | |
350 | } | |
296c0905 C |
351 | } |
352 | ||
4b8f09fa | 353 | return activityPubResponse(activityPubContextify(videoCommentObject), res) |
da854ddd | 354 | } |
7006bc63 | 355 | |
c48e82b5 | 356 | async function videoRedundancyController (req: express.Request, res: express.Response) { |
dae86118 | 357 | const videoRedundancy = res.locals.videoRedundancy |
de94ac86 C |
358 | |
359 | if (redirectIfNotOwned(videoRedundancy.url, res)) return | |
8d1fa36a | 360 | |
c48e82b5 C |
361 | const serverActor = await getServerActor() |
362 | ||
363 | const audience = getAudience(serverActor) | |
364 | const object = audiencify(videoRedundancy.toActivityPubObject(), audience) | |
365 | ||
366 | if (req.path.endsWith('/activity')) { | |
367 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) | |
084a2cd0 | 368 | return activityPubResponse(activityPubContextify(data, 'CacheFile'), res) |
c48e82b5 C |
369 | } |
370 | ||
084a2cd0 | 371 | return activityPubResponse(activityPubContextify(object, 'CacheFile'), res) |
c48e82b5 C |
372 | } |
373 | ||
418d092a | 374 | async function videoPlaylistController (req: express.Request, res: express.Response) { |
453e83ea | 375 | const playlist = res.locals.videoPlaylistFull |
418d092a | 376 | |
de94ac86 C |
377 | if (redirectIfNotOwned(playlist.url, res)) return |
378 | ||
df0b219d C |
379 | // We need more attributes |
380 | playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId) | |
381 | ||
382 | const json = await playlist.toActivityPubObject(req.query.page, null) | |
418d092a C |
383 | const audience = getAudience(playlist.OwnerAccount.Actor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC) |
384 | const object = audiencify(json, audience) | |
385 | ||
386 | return activityPubResponse(activityPubContextify(object), res) | |
387 | } | |
388 | ||
a1587156 | 389 | function videoPlaylistElementController (req: express.Request, res: express.Response) { |
b5fecbf4 | 390 | const videoPlaylistElement = res.locals.videoPlaylistElementAP |
418d092a | 391 | |
de94ac86 C |
392 | if (redirectIfNotOwned(videoPlaylistElement.url, res)) return |
393 | ||
418d092a C |
394 | const json = videoPlaylistElement.toActivityPubObject() |
395 | return activityPubResponse(activityPubContextify(json), res) | |
396 | } | |
397 | ||
7006bc63 C |
398 | // --------------------------------------------------------------------------- |
399 | ||
453e83ea | 400 | async function actorFollowing (req: express.Request, actor: MActorId) { |
8fffe21a C |
401 | const handler = (start: number, count: number) => { |
402 | return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count) | |
403 | } | |
7006bc63 | 404 | |
6dd9de95 | 405 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
7006bc63 C |
406 | } |
407 | ||
453e83ea | 408 | async function actorFollowers (req: express.Request, actor: MActorId) { |
8fffe21a | 409 | const handler = (start: number, count: number) => { |
418d092a C |
410 | return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count) |
411 | } | |
412 | ||
6dd9de95 | 413 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
418d092a C |
414 | } |
415 | ||
7405b6ba | 416 | async function actorPlaylists (req: express.Request, options: { account: MAccountId } | { channel: MChannelId }) { |
418d092a | 417 | const handler = (start: number, count: number) => { |
7405b6ba | 418 | return VideoPlaylistModel.listPublicUrlsOfForAP(options, start, count) |
8fffe21a | 419 | } |
7006bc63 | 420 | |
6dd9de95 | 421 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
7006bc63 | 422 | } |
4b8f09fa | 423 | |
7eba5e1f | 424 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideoId, url: string) { |
8fffe21a C |
425 | const handler = async (start: number, count: number) => { |
426 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) | |
427 | return { | |
428 | total: result.count, | |
5c6d985f | 429 | data: result.rows.map(r => r.url) |
8fffe21a C |
430 | } |
431 | } | |
432 | return activityPubCollectionPagination(url, handler, req.query.page) | |
4b8f09fa | 433 | } |
de94ac86 C |
434 | |
435 | function redirectIfNotOwned (url: string, res: express.Response) { | |
436 | if (url.startsWith(WEBSERVER.URL) === false) { | |
437 | res.redirect(url) | |
438 | return true | |
439 | } | |
440 | ||
441 | return false | |
442 | } |