diff options
author | Chocobozzz <me@florianbigard.com> | 2023-03-10 12:01:21 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-03-10 14:42:18 +0100 |
commit | 866b5d3f5230204d611a556260102996c1aefe10 (patch) | |
tree | d6d1e900ce81a7f1edc121089c10a67abba855eb /server/controllers/activitypub | |
parent | 4265d90b0061399e23b816e3880ee1be47ead96f (diff) | |
download | PeerTube-866b5d3f5230204d611a556260102996c1aefe10.tar.gz PeerTube-866b5d3f5230204d611a556260102996c1aefe10.tar.zst PeerTube-866b5d3f5230204d611a556260102996c1aefe10.zip |
Add ability for plugins to alter video jsonld
Diffstat (limited to 'server/controllers/activitypub')
-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 | } |