diff options
author | Chocobozzz <me@florianbigard.com> | 2023-03-10 12:01:21 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-03-10 15:45:52 +0100 |
commit | 3b504f6ed4e890bebb46d0481aba15b43050323a (patch) | |
tree | bbe4c1bc529fec28e0b46263ec92f7c2260ba65a /server/controllers | |
parent | 4899138ec5995075c3681ccbd9f6b163fb915991 (diff) | |
download | PeerTube-3b504f6ed4e890bebb46d0481aba15b43050323a.tar.gz PeerTube-3b504f6ed4e890bebb46d0481aba15b43050323a.tar.zst PeerTube-3b504f6ed4e890bebb46d0481aba15b43050323a.zip |
Add ability for plugins to alter video jsonld
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 22 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 2 | ||||
-rw-r--r-- | server/controllers/activitypub/utils.ts | 4 |
3 files changed, 15 insertions, 13 deletions
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( | |||
48 | [ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ], | 48 | [ '/accounts?/:name', '/accounts?/:name/video-channels', '/a/:name', '/a/:name/video-channels' ], |
49 | executeIfActivityPub, | 49 | executeIfActivityPub, |
50 | asyncMiddleware(localAccountValidator), | 50 | asyncMiddleware(localAccountValidator), |
51 | accountController | 51 | asyncMiddleware(accountController) |
52 | ) | 52 | ) |
53 | activityPubClientRouter.get('/accounts?/:name/followers', | 53 | activityPubClientRouter.get('/accounts?/:name/followers', |
54 | executeIfActivityPub, | 54 | executeIfActivityPub, |
@@ -69,13 +69,13 @@ activityPubClientRouter.get('/accounts?/:name/likes/:videoId', | |||
69 | executeIfActivityPub, | 69 | executeIfActivityPub, |
70 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), | 70 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
71 | asyncMiddleware(getAccountVideoRateValidatorFactory('like')), | 71 | asyncMiddleware(getAccountVideoRateValidatorFactory('like')), |
72 | getAccountVideoRateFactory('like') | 72 | asyncMiddleware(getAccountVideoRateFactory('like')) |
73 | ) | 73 | ) |
74 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | 74 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', |
75 | executeIfActivityPub, | 75 | executeIfActivityPub, |
76 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), | 76 | cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS), |
77 | asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), | 77 | asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), |
78 | getAccountVideoRateFactory('dislike') | 78 | asyncMiddleware(getAccountVideoRateFactory('dislike')) |
79 | ) | 79 | ) |
80 | 80 | ||
81 | activityPubClientRouter.get( | 81 | activityPubClientRouter.get( |
@@ -131,7 +131,7 @@ activityPubClientRouter.get( | |||
131 | executeIfActivityPub, | 131 | executeIfActivityPub, |
132 | asyncMiddleware(videoChannelsNameWithHostValidator), | 132 | asyncMiddleware(videoChannelsNameWithHostValidator), |
133 | ensureIsLocalChannel, | 133 | ensureIsLocalChannel, |
134 | videoChannelController | 134 | asyncMiddleware(videoChannelController) |
135 | ) | 135 | ) |
136 | activityPubClientRouter.get('/video-channels/:nameWithHost/followers', | 136 | activityPubClientRouter.get('/video-channels/:nameWithHost/followers', |
137 | executeIfActivityPub, | 137 | executeIfActivityPub, |
@@ -172,13 +172,13 @@ activityPubClientRouter.get( | |||
172 | activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId', | 172 | activityPubClientRouter.get('/video-playlists/:playlistId/videos/:playlistElementId', |
173 | executeIfActivityPub, | 173 | executeIfActivityPub, |
174 | asyncMiddleware(videoPlaylistElementAPGetValidator), | 174 | asyncMiddleware(videoPlaylistElementAPGetValidator), |
175 | videoPlaylistElementController | 175 | asyncMiddleware(videoPlaylistElementController) |
176 | ) | 176 | ) |
177 | 177 | ||
178 | activityPubClientRouter.get('/videos/local-viewer/:localViewerId', | 178 | activityPubClientRouter.get('/videos/local-viewer/:localViewerId', |
179 | executeIfActivityPub, | 179 | executeIfActivityPub, |
180 | asyncMiddleware(getVideoLocalViewerValidator), | 180 | asyncMiddleware(getVideoLocalViewerValidator), |
181 | getVideoLocalViewerController | 181 | asyncMiddleware(getVideoLocalViewerController) |
182 | ) | 182 | ) |
183 | 183 | ||
184 | // --------------------------------------------------------------------------- | 184 | // --------------------------------------------------------------------------- |
@@ -189,10 +189,10 @@ export { | |||
189 | 189 | ||
190 | // --------------------------------------------------------------------------- | 190 | // --------------------------------------------------------------------------- |
191 | 191 | ||
192 | function accountController (req: express.Request, res: express.Response) { | 192 | async function accountController (req: express.Request, res: express.Response) { |
193 | const account = res.locals.account | 193 | const account = res.locals.account |
194 | 194 | ||
195 | return activityPubResponse(activityPubContextify(account.toActivityPubObject(), 'Actor'), res) | 195 | return activityPubResponse(activityPubContextify(await account.toActivityPubObject(), 'Actor'), res) |
196 | } | 196 | } |
197 | 197 | ||
198 | async function accountFollowersController (req: express.Request, res: express.Response) { | 198 | async function accountFollowersController (req: express.Request, res: express.Response) { |
@@ -246,7 +246,7 @@ async function videoController (req: express.Request, res: express.Response) { | |||
246 | const videoWithCaptions = Object.assign(video, { VideoCaptions: captions }) | 246 | const videoWithCaptions = Object.assign(video, { VideoCaptions: captions }) |
247 | 247 | ||
248 | const audience = getAudience(videoWithCaptions.VideoChannel.Account.Actor, videoWithCaptions.privacy === VideoPrivacy.PUBLIC) | 248 | const audience = getAudience(videoWithCaptions.VideoChannel.Account.Actor, videoWithCaptions.privacy === VideoPrivacy.PUBLIC) |
249 | const videoObject = audiencify(videoWithCaptions.toActivityPubObject(), audience) | 249 | const videoObject = audiencify(await videoWithCaptions.toActivityPubObject(), audience) |
250 | 250 | ||
251 | if (req.path.endsWith('/activity')) { | 251 | if (req.path.endsWith('/activity')) { |
252 | const data = buildCreateActivity(videoWithCaptions.url, video.VideoChannel.Account.Actor, videoObject, audience) | 252 | const data = buildCreateActivity(videoWithCaptions.url, video.VideoChannel.Account.Actor, videoObject, audience) |
@@ -321,10 +321,10 @@ async function videoCommentsController (req: express.Request, res: express.Respo | |||
321 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) | 321 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) |
322 | } | 322 | } |
323 | 323 | ||
324 | function videoChannelController (req: express.Request, res: express.Response) { | 324 | async function videoChannelController (req: express.Request, res: express.Response) { |
325 | const videoChannel = res.locals.videoChannel | 325 | const videoChannel = res.locals.videoChannel |
326 | 326 | ||
327 | return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject(), 'Actor'), res) | 327 | return activityPubResponse(activityPubContextify(await videoChannel.toActivityPubObject(), 'Actor'), res) |
328 | } | 328 | } |
329 | 329 | ||
330 | async function videoChannelFollowersController (req: express.Request, res: express.Response) { | 330 | 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 | |||
63 | 63 | ||
64 | activities.push(announceActivity) | 64 | activities.push(announceActivity) |
65 | } else { | 65 | } else { |
66 | const videoObject = video.toActivityPubObject() | 66 | const videoObject = await video.toActivityPubObject() |
67 | const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience) | 67 | const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience) |
68 | 68 | ||
69 | activities.push(createActivity) | 69 | 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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | 2 | ||
3 | function activityPubResponse (data: any, res: express.Response) { | 3 | async function activityPubResponse (promise: Promise<any>, res: express.Response) { |
4 | const data = await promise | ||
5 | |||
4 | return res.type('application/activity+json; charset=utf-8') | 6 | return res.type('application/activity+json; charset=utf-8') |
5 | .json(data) | 7 | .json(data) |
6 | } | 8 | } |