diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-23 16:14:33 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-24 09:40:46 +0100 |
commit | a219c9100b3ce8774d454497d46be87465bf664e (patch) | |
tree | caa869e47919a9e23cc86dcece1100e239683b8c /server/controllers | |
parent | 7e98a7df7d04e19ba67163a86c7b876d78d76839 (diff) | |
download | PeerTube-a219c9100b3ce8774d454497d46be87465bf664e.tar.gz PeerTube-a219c9100b3ce8774d454497d46be87465bf664e.tar.zst PeerTube-a219c9100b3ce8774d454497d46be87465bf664e.zip |
Refactor AP context builder
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 38 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 2 |
2 files changed, 20 insertions, 20 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 99637dbab..d0f761009 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -186,35 +186,35 @@ export { | |||
186 | function accountController (req: express.Request, res: express.Response) { | 186 | function accountController (req: express.Request, res: express.Response) { |
187 | const account = res.locals.account | 187 | const account = res.locals.account |
188 | 188 | ||
189 | return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res) | 189 | return activityPubResponse(activityPubContextify(account.toActivityPubObject(), 'Actor'), res) |
190 | } | 190 | } |
191 | 191 | ||
192 | async function accountFollowersController (req: express.Request, res: express.Response) { | 192 | async function accountFollowersController (req: express.Request, res: express.Response) { |
193 | const account = res.locals.account | 193 | const account = res.locals.account |
194 | const activityPubResult = await actorFollowers(req, account.Actor) | 194 | const activityPubResult = await actorFollowers(req, account.Actor) |
195 | 195 | ||
196 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 196 | return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res) |
197 | } | 197 | } |
198 | 198 | ||
199 | async function accountFollowingController (req: express.Request, res: express.Response) { | 199 | async function accountFollowingController (req: express.Request, res: express.Response) { |
200 | const account = res.locals.account | 200 | const account = res.locals.account |
201 | const activityPubResult = await actorFollowing(req, account.Actor) | 201 | const activityPubResult = await actorFollowing(req, account.Actor) |
202 | 202 | ||
203 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 203 | return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res) |
204 | } | 204 | } |
205 | 205 | ||
206 | async function accountPlaylistsController (req: express.Request, res: express.Response) { | 206 | async function accountPlaylistsController (req: express.Request, res: express.Response) { |
207 | const account = res.locals.account | 207 | const account = res.locals.account |
208 | const activityPubResult = await actorPlaylists(req, { account }) | 208 | const activityPubResult = await actorPlaylists(req, { account }) |
209 | 209 | ||
210 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 210 | return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res) |
211 | } | 211 | } |
212 | 212 | ||
213 | async function videoChannelPlaylistsController (req: express.Request, res: express.Response) { | 213 | async function videoChannelPlaylistsController (req: express.Request, res: express.Response) { |
214 | const channel = res.locals.videoChannel | 214 | const channel = res.locals.videoChannel |
215 | const activityPubResult = await actorPlaylists(req, { channel }) | 215 | const activityPubResult = await actorPlaylists(req, { channel }) |
216 | 216 | ||
217 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 217 | return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res) |
218 | } | 218 | } |
219 | 219 | ||
220 | function getAccountVideoRateFactory (rateType: VideoRateType) { | 220 | function getAccountVideoRateFactory (rateType: VideoRateType) { |
@@ -226,7 +226,7 @@ function getAccountVideoRateFactory (rateType: VideoRateType) { | |||
226 | ? buildLikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video) | 226 | ? buildLikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video) |
227 | : buildDislikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video) | 227 | : buildDislikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video) |
228 | 228 | ||
229 | return activityPubResponse(activityPubContextify(APObject), res) | 229 | return activityPubResponse(activityPubContextify(APObject, 'Rate'), res) |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
@@ -244,10 +244,10 @@ async function videoController (req: express.Request, res: express.Response) { | |||
244 | 244 | ||
245 | if (req.path.endsWith('/activity')) { | 245 | if (req.path.endsWith('/activity')) { |
246 | const data = buildCreateActivity(videoWithCaptions.url, video.VideoChannel.Account.Actor, videoObject, audience) | 246 | const data = buildCreateActivity(videoWithCaptions.url, video.VideoChannel.Account.Actor, videoObject, audience) |
247 | return activityPubResponse(activityPubContextify(data), res) | 247 | return activityPubResponse(activityPubContextify(data, 'Video'), res) |
248 | } | 248 | } |
249 | 249 | ||
250 | return activityPubResponse(activityPubContextify(videoObject), res) | 250 | return activityPubResponse(activityPubContextify(videoObject, 'Video'), res) |
251 | } | 251 | } |
252 | 252 | ||
253 | async function videoAnnounceController (req: express.Request, res: express.Response) { | 253 | async function videoAnnounceController (req: express.Request, res: express.Response) { |
@@ -274,7 +274,7 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp | |||
274 | } | 274 | } |
275 | const json = await activityPubCollectionPagination(getLocalVideoSharesActivityPubUrl(video), handler, req.query.page) | 275 | const json = await activityPubCollectionPagination(getLocalVideoSharesActivityPubUrl(video), handler, req.query.page) |
276 | 276 | ||
277 | return activityPubResponse(activityPubContextify(json), res) | 277 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) |
278 | } | 278 | } |
279 | 279 | ||
280 | async function videoLikesController (req: express.Request, res: express.Response) { | 280 | async function videoLikesController (req: express.Request, res: express.Response) { |
@@ -284,7 +284,7 @@ async function videoLikesController (req: express.Request, res: express.Response | |||
284 | 284 | ||
285 | const json = await videoRates(req, 'like', video, getLocalVideoLikesActivityPubUrl(video)) | 285 | const json = await videoRates(req, 'like', video, getLocalVideoLikesActivityPubUrl(video)) |
286 | 286 | ||
287 | return activityPubResponse(activityPubContextify(json), res) | 287 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) |
288 | } | 288 | } |
289 | 289 | ||
290 | async function videoDislikesController (req: express.Request, res: express.Response) { | 290 | async function videoDislikesController (req: express.Request, res: express.Response) { |
@@ -294,7 +294,7 @@ async function videoDislikesController (req: express.Request, res: express.Respo | |||
294 | 294 | ||
295 | const json = await videoRates(req, 'dislike', video, getLocalVideoDislikesActivityPubUrl(video)) | 295 | const json = await videoRates(req, 'dislike', video, getLocalVideoDislikesActivityPubUrl(video)) |
296 | 296 | ||
297 | return activityPubResponse(activityPubContextify(json), res) | 297 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) |
298 | } | 298 | } |
299 | 299 | ||
300 | async function videoCommentsController (req: express.Request, res: express.Response) { | 300 | async function videoCommentsController (req: express.Request, res: express.Response) { |
@@ -312,27 +312,27 @@ async function videoCommentsController (req: express.Request, res: express.Respo | |||
312 | } | 312 | } |
313 | const json = await activityPubCollectionPagination(getLocalVideoCommentsActivityPubUrl(video), handler, req.query.page) | 313 | const json = await activityPubCollectionPagination(getLocalVideoCommentsActivityPubUrl(video), handler, req.query.page) |
314 | 314 | ||
315 | return activityPubResponse(activityPubContextify(json), res) | 315 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) |
316 | } | 316 | } |
317 | 317 | ||
318 | function videoChannelController (req: express.Request, res: express.Response) { | 318 | function videoChannelController (req: express.Request, res: express.Response) { |
319 | const videoChannel = res.locals.videoChannel | 319 | const videoChannel = res.locals.videoChannel |
320 | 320 | ||
321 | return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) | 321 | return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject(), 'Actor'), res) |
322 | } | 322 | } |
323 | 323 | ||
324 | async function videoChannelFollowersController (req: express.Request, res: express.Response) { | 324 | async function videoChannelFollowersController (req: express.Request, res: express.Response) { |
325 | const videoChannel = res.locals.videoChannel | 325 | const videoChannel = res.locals.videoChannel |
326 | const activityPubResult = await actorFollowers(req, videoChannel.Actor) | 326 | const activityPubResult = await actorFollowers(req, videoChannel.Actor) |
327 | 327 | ||
328 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 328 | return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res) |
329 | } | 329 | } |
330 | 330 | ||
331 | async function videoChannelFollowingController (req: express.Request, res: express.Response) { | 331 | async function videoChannelFollowingController (req: express.Request, res: express.Response) { |
332 | const videoChannel = res.locals.videoChannel | 332 | const videoChannel = res.locals.videoChannel |
333 | const activityPubResult = await actorFollowing(req, videoChannel.Actor) | 333 | const activityPubResult = await actorFollowing(req, videoChannel.Actor) |
334 | 334 | ||
335 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 335 | return activityPubResponse(activityPubContextify(activityPubResult, 'Collection'), res) |
336 | } | 336 | } |
337 | 337 | ||
338 | async function videoCommentController (req: express.Request, res: express.Response) { | 338 | async function videoCommentController (req: express.Request, res: express.Response) { |
@@ -350,11 +350,11 @@ async function videoCommentController (req: express.Request, res: express.Respon | |||
350 | 350 | ||
351 | if (req.path.endsWith('/activity')) { | 351 | if (req.path.endsWith('/activity')) { |
352 | const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) | 352 | const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) |
353 | return activityPubResponse(activityPubContextify(data), res) | 353 | return activityPubResponse(activityPubContextify(data, 'Comment'), res) |
354 | } | 354 | } |
355 | } | 355 | } |
356 | 356 | ||
357 | return activityPubResponse(activityPubContextify(videoCommentObject), res) | 357 | return activityPubResponse(activityPubContextify(videoCommentObject, 'Comment'), res) |
358 | } | 358 | } |
359 | 359 | ||
360 | async function videoRedundancyController (req: express.Request, res: express.Response) { | 360 | async function videoRedundancyController (req: express.Request, res: express.Response) { |
@@ -387,7 +387,7 @@ async function videoPlaylistController (req: express.Request, res: express.Respo | |||
387 | const audience = getAudience(playlist.OwnerAccount.Actor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC) | 387 | const audience = getAudience(playlist.OwnerAccount.Actor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC) |
388 | const object = audiencify(json, audience) | 388 | const object = audiencify(json, audience) |
389 | 389 | ||
390 | return activityPubResponse(activityPubContextify(object), res) | 390 | return activityPubResponse(activityPubContextify(object, 'Playlist'), res) |
391 | } | 391 | } |
392 | 392 | ||
393 | function videoPlaylistElementController (req: express.Request, res: express.Response) { | 393 | function videoPlaylistElementController (req: express.Request, res: express.Response) { |
@@ -396,7 +396,7 @@ function videoPlaylistElementController (req: express.Request, res: express.Resp | |||
396 | if (redirectIfNotOwned(videoPlaylistElement.url, res)) return | 396 | if (redirectIfNotOwned(videoPlaylistElement.url, res)) return |
397 | 397 | ||
398 | const json = videoPlaylistElement.toActivityPubObject() | 398 | const json = videoPlaylistElement.toActivityPubObject() |
399 | return activityPubResponse(activityPubContextify(json), res) | 399 | return activityPubResponse(activityPubContextify(json, 'Playlist'), res) |
400 | } | 400 | } |
401 | 401 | ||
402 | // --------------------------------------------------------------------------- | 402 | // --------------------------------------------------------------------------- |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index 4e7a3afeb..f385c9927 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -45,7 +45,7 @@ async function outboxController (req: express.Request, res: express.Response) { | |||
45 | const handler = (start: number, count: number) => buildActivities(actor, start, count) | 45 | const handler = (start: number, count: number) => buildActivities(actor, start, count) |
46 | const json = await activityPubCollectionPagination(actorOutboxUrl, handler, req.query.page, req.query.size) | 46 | const json = await activityPubCollectionPagination(actorOutboxUrl, handler, req.query.page, req.query.size) |
47 | 47 | ||
48 | return activityPubResponse(activityPubContextify(json), res) | 48 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) |
49 | } | 49 | } |
50 | 50 | ||
51 | async function buildActivities (actor: MActorLight, start: number, count: number) { | 51 | async function buildActivities (actor: MActorLight, start: number, count: number) { |