From 866b5d3f5230204d611a556260102996c1aefe10 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Mar 2023 12:01:21 +0100 Subject: Add ability for plugins to alter video jsonld --- server/controllers/activitypub/client.ts | 22 +++++++++++----------- server/controllers/activitypub/outbox.ts | 2 +- server/controllers/activitypub/utils.ts | 4 +++- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index def320730..750e3091c 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -48,7 +48,7 @@ activityPubClientRouter.get( [ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ], executeIfActivityPub, asyncMiddleware(localAccountValidator), - accountController + asyncMiddleware(accountController) ) activityPubClientRouter.get('/accounts?/:name/followers', executeIfActivityPub, @@ -69,13 +69,13 @@ activityPubClientRouter.get('/accounts?/:name/likes/:videoId', executeIfActivityPub, cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), asyncMiddleware(getAccountVideoRateValidatorFactory('like')), - getAccountVideoRateFactory('like') + asyncMiddleware(getAccountVideoRateFactory('like')) ) activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', executeIfActivityPub, cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), - getAccountVideoRateFactory('dislike') + asyncMiddleware(getAccountVideoRateFactory('dislike')) ) activityPubClientRouter.get( @@ -131,7 +131,7 @@ activityPubClientRouter.get( executeIfActivityPub, asyncMiddleware(videoChannelsNameWithHostValidator), ensureIsLocalChannel, - videoChannelController + asyncMiddleware(videoChannelController) ) activityPubClientRouter.get('/video-channels/:nameWithHost/followers', executeIfActivityPub, @@ -172,13 +172,13 @@ activityPubClientRouter.get( activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId', executeIfActivityPub, asyncMiddleware(videoPlaylistElementAPGetValidator), - videoPlaylistElementController + asyncMiddleware(videoPlaylistElementController) ) activityPubClientRouter.get('/videos/local-viewer/:localViewerId', executeIfActivityPub, asyncMiddleware(getVideoLocalViewerValidator), - getVideoLocalViewerController + asyncMiddleware(getVideoLocalViewerController) ) // --------------------------------------------------------------------------- @@ -189,10 +189,10 @@ export { // --------------------------------------------------------------------------- -function accountController (req: express.Request, res: express.Response) { +async function accountController (req: express.Request, res: express.Response) { const account = res.locals.account - return activityPubResponse(activityPubContextify(account.toActivityPubObject(), 'Actor'), res) + return activityPubResponse(activityPubContextify(await account.toActivityPubObject(), 'Actor'), res) } async function accountFollowersController (req: express.Request, res: express.Response) { @@ -246,7 +246,7 @@ async function videoController (req: express.Request, res: express.Response) { const videoWithCaptions = Object.assign(video, { VideoCaptions: captions }) const audience = getAudience(videoWithCaptions.VideoChannel.Account.Actor, videoWithCaptions.privacy === VideoPrivacy.PUBLIC) - const videoObject = audiencify(videoWithCaptions.toActivityPubObject(), audience) + const videoObject = audiencify(await videoWithCaptions.toActivityPubObject(), audience) if (req.path.endsWith('/activity')) { const data = buildCreateActivity(videoWithCaptions.url, video.VideoChannel.Account.Actor, videoObject, audience) @@ -321,10 +321,10 @@ async function videoCommentsController (req: express.Request, res: express.Respo return activityPubResponse(activityPubContextify(json, 'Collection'), res) } -function videoChannelController (req: express.Request, res: express.Response) { +async function videoChannelController (req: express.Request, res: express.Response) { const videoChannel = res.locals.videoChannel - return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject(), 'Actor'), res) + return activityPubResponse(activityPubContextify(await videoChannel.toActivityPubObject(), 'Actor'), res) } async function videoChannelFollowersController (req: express.Request, res: express.Response) { diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index f385c9927..681a5660c 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts @@ -63,7 +63,7 @@ async function buildActivities (actor: MActorLight, start: number, count: number activities.push(announceActivity) } else { - const videoObject = video.toActivityPubObject() + const videoObject = await video.toActivityPubObject() const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience) activities.push(createActivity) diff --git a/server/controllers/activitypub/utils.ts b/server/controllers/activitypub/utils.ts index f851ef652..5de38eb43 100644 --- a/server/controllers/activitypub/utils.ts +++ b/server/controllers/activitypub/utils.ts @@ -1,6 +1,8 @@ import express from 'express' -function activityPubResponse (data: any, res: express.Response) { +async function activityPubResponse (promise: Promise, res: express.Response) { + const data = await promise + return res.type('application/activity+json; charset=utf-8') .json(data) } -- cgit v1.2.3