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