diff options
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 49 | ||||
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 6 |
2 files changed, 30 insertions, 25 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 62412cd62..84828e7e0 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | // Intercept ActivityPub client requests | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' | 2 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' |
4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | 3 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
@@ -14,7 +13,7 @@ import { | |||
14 | videosCustomGetValidator, | 13 | videosCustomGetValidator, |
15 | videosShareValidator | 14 | videosShareValidator |
16 | } from '../../middlewares' | 15 | } from '../../middlewares' |
17 | import { getAccountVideoRateValidator, videoCommentGetValidator } from '../../middlewares/validators' | 16 | import { getAccountVideoRateValidatorFactory, videoCommentGetValidator } from '../../middlewares/validators' |
18 | import { AccountModel } from '../../models/account/account' | 17 | import { AccountModel } from '../../models/account/account' |
19 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 18 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
20 | import { VideoModel } from '../../models/video/video' | 19 | import { VideoModel } from '../../models/video/video' |
@@ -37,10 +36,12 @@ import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' | |||
37 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' | 36 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' |
38 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 37 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
39 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 38 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
40 | import { MAccountId, MActorId, MVideo, MVideoAPWithoutCaption } from '@server/typings/models' | 39 | import { MAccountId, MActorId, MVideoAPWithoutCaption, MVideoId } from '@server/typings/models' |
41 | 40 | ||
42 | const activityPubClientRouter = express.Router() | 41 | const activityPubClientRouter = express.Router() |
43 | 42 | ||
43 | // Intercept ActivityPub client requests | ||
44 | |||
44 | activityPubClientRouter.get('/accounts?/:name', | 45 | activityPubClientRouter.get('/accounts?/:name', |
45 | executeIfActivityPub, | 46 | executeIfActivityPub, |
46 | asyncMiddleware(localAccountValidator), | 47 | asyncMiddleware(localAccountValidator), |
@@ -63,13 +64,13 @@ activityPubClientRouter.get('/accounts?/:name/playlists', | |||
63 | ) | 64 | ) |
64 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', | 65 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', |
65 | executeIfActivityPub, | 66 | executeIfActivityPub, |
66 | asyncMiddleware(getAccountVideoRateValidator('like')), | 67 | asyncMiddleware(getAccountVideoRateValidatorFactory('like')), |
67 | getAccountVideoRate('like') | 68 | getAccountVideoRateFactory('like') |
68 | ) | 69 | ) |
69 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | 70 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', |
70 | executeIfActivityPub, | 71 | executeIfActivityPub, |
71 | asyncMiddleware(getAccountVideoRateValidator('dislike')), | 72 | asyncMiddleware(getAccountVideoRateValidatorFactory('dislike')), |
72 | getAccountVideoRate('dislike') | 73 | getAccountVideoRateFactory('dislike') |
73 | ) | 74 | ) |
74 | 75 | ||
75 | activityPubClientRouter.get('/videos/watch/:id', | 76 | activityPubClientRouter.get('/videos/watch/:id', |
@@ -85,7 +86,7 @@ activityPubClientRouter.get('/videos/watch/:id/activity', | |||
85 | ) | 86 | ) |
86 | activityPubClientRouter.get('/videos/watch/:id/announces', | 87 | activityPubClientRouter.get('/videos/watch/:id/announces', |
87 | executeIfActivityPub, | 88 | executeIfActivityPub, |
88 | asyncMiddleware(videosCustomGetValidator('only-video')), | 89 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
89 | asyncMiddleware(videoAnnouncesController) | 90 | asyncMiddleware(videoAnnouncesController) |
90 | ) | 91 | ) |
91 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | 92 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', |
@@ -95,17 +96,17 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | |||
95 | ) | 96 | ) |
96 | activityPubClientRouter.get('/videos/watch/:id/likes', | 97 | activityPubClientRouter.get('/videos/watch/:id/likes', |
97 | executeIfActivityPub, | 98 | executeIfActivityPub, |
98 | asyncMiddleware(videosCustomGetValidator('only-video')), | 99 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
99 | asyncMiddleware(videoLikesController) | 100 | asyncMiddleware(videoLikesController) |
100 | ) | 101 | ) |
101 | activityPubClientRouter.get('/videos/watch/:id/dislikes', | 102 | activityPubClientRouter.get('/videos/watch/:id/dislikes', |
102 | executeIfActivityPub, | 103 | executeIfActivityPub, |
103 | asyncMiddleware(videosCustomGetValidator('only-video')), | 104 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
104 | asyncMiddleware(videoDislikesController) | 105 | asyncMiddleware(videoDislikesController) |
105 | ) | 106 | ) |
106 | activityPubClientRouter.get('/videos/watch/:id/comments', | 107 | activityPubClientRouter.get('/videos/watch/:id/comments', |
107 | executeIfActivityPub, | 108 | executeIfActivityPub, |
108 | asyncMiddleware(videosCustomGetValidator('only-video')), | 109 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
109 | asyncMiddleware(videoCommentsController) | 110 | asyncMiddleware(videoCommentsController) |
110 | ) | 111 | ) |
111 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', | 112 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', |
@@ -122,7 +123,7 @@ activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId/activity | |||
122 | activityPubClientRouter.get('/video-channels/:name', | 123 | activityPubClientRouter.get('/video-channels/:name', |
123 | executeIfActivityPub, | 124 | executeIfActivityPub, |
124 | asyncMiddleware(localVideoChannelValidator), | 125 | asyncMiddleware(localVideoChannelValidator), |
125 | asyncMiddleware(videoChannelController) | 126 | videoChannelController |
126 | ) | 127 | ) |
127 | activityPubClientRouter.get('/video-channels/:name/followers', | 128 | activityPubClientRouter.get('/video-channels/:name/followers', |
128 | executeIfActivityPub, | 129 | executeIfActivityPub, |
@@ -154,7 +155,7 @@ activityPubClientRouter.get('/video-playlists/:playlistId', | |||
154 | activityPubClientRouter.get('/video-playlists/:playlistId/:videoId', | 155 | activityPubClientRouter.get('/video-playlists/:playlistId/:videoId', |
155 | executeIfActivityPub, | 156 | executeIfActivityPub, |
156 | asyncMiddleware(videoPlaylistElementAPGetValidator), | 157 | asyncMiddleware(videoPlaylistElementAPGetValidator), |
157 | asyncMiddleware(videoPlaylistElementController) | 158 | videoPlaylistElementController |
158 | ) | 159 | ) |
159 | 160 | ||
160 | // --------------------------------------------------------------------------- | 161 | // --------------------------------------------------------------------------- |
@@ -192,7 +193,7 @@ async function accountPlaylistsController (req: express.Request, res: express.Re | |||
192 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 193 | return activityPubResponse(activityPubContextify(activityPubResult), res) |
193 | } | 194 | } |
194 | 195 | ||
195 | function getAccountVideoRate (rateType: VideoRateType) { | 196 | function getAccountVideoRateFactory (rateType: VideoRateType) { |
196 | return (req: express.Request, res: express.Response) => { | 197 | return (req: express.Request, res: express.Response) => { |
197 | const accountVideoRate = res.locals.accountVideoRate | 198 | const accountVideoRate = res.locals.accountVideoRate |
198 | 199 | ||
@@ -234,11 +235,11 @@ async function videoAnnounceController (req: express.Request, res: express.Respo | |||
234 | 235 | ||
235 | const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll, undefined) | 236 | const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll, undefined) |
236 | 237 | ||
237 | return activityPubResponse(activityPubContextify(activity), res) | 238 | return activityPubResponse(activityPubContextify(activity, 'Announce'), res) |
238 | } | 239 | } |
239 | 240 | ||
240 | async function videoAnnouncesController (req: express.Request, res: express.Response) { | 241 | async function videoAnnouncesController (req: express.Request, res: express.Response) { |
241 | const video = res.locals.onlyVideo | 242 | const video = res.locals.onlyImmutableVideo |
242 | 243 | ||
243 | const handler = async (start: number, count: number) => { | 244 | const handler = async (start: number, count: number) => { |
244 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) | 245 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) |
@@ -253,21 +254,21 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp | |||
253 | } | 254 | } |
254 | 255 | ||
255 | async function videoLikesController (req: express.Request, res: express.Response) { | 256 | async function videoLikesController (req: express.Request, res: express.Response) { |
256 | const video = res.locals.onlyVideo | 257 | const video = res.locals.onlyImmutableVideo |
257 | const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) | 258 | const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) |
258 | 259 | ||
259 | return activityPubResponse(activityPubContextify(json), res) | 260 | return activityPubResponse(activityPubContextify(json), res) |
260 | } | 261 | } |
261 | 262 | ||
262 | async function videoDislikesController (req: express.Request, res: express.Response) { | 263 | async function videoDislikesController (req: express.Request, res: express.Response) { |
263 | const video = res.locals.onlyVideo | 264 | const video = res.locals.onlyImmutableVideo |
264 | const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) | 265 | const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) |
265 | 266 | ||
266 | return activityPubResponse(activityPubContextify(json), res) | 267 | return activityPubResponse(activityPubContextify(json), res) |
267 | } | 268 | } |
268 | 269 | ||
269 | async function videoCommentsController (req: express.Request, res: express.Response) { | 270 | async function videoCommentsController (req: express.Request, res: express.Response) { |
270 | const video = res.locals.onlyVideo | 271 | const video = res.locals.onlyImmutableVideo |
271 | 272 | ||
272 | const handler = async (start: number, count: number) => { | 273 | const handler = async (start: number, count: number) => { |
273 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) | 274 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) |
@@ -281,7 +282,7 @@ async function videoCommentsController (req: express.Request, res: express.Respo | |||
281 | return activityPubResponse(activityPubContextify(json), res) | 282 | return activityPubResponse(activityPubContextify(json), res) |
282 | } | 283 | } |
283 | 284 | ||
284 | async function videoChannelController (req: express.Request, res: express.Response) { | 285 | function videoChannelController (req: express.Request, res: express.Response) { |
285 | const videoChannel = res.locals.videoChannel | 286 | const videoChannel = res.locals.videoChannel |
286 | 287 | ||
287 | return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) | 288 | return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) |
@@ -334,10 +335,10 @@ async function videoRedundancyController (req: express.Request, res: express.Res | |||
334 | 335 | ||
335 | if (req.path.endsWith('/activity')) { | 336 | if (req.path.endsWith('/activity')) { |
336 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) | 337 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) |
337 | return activityPubResponse(activityPubContextify(data), res) | 338 | return activityPubResponse(activityPubContextify(data, 'CacheFile'), res) |
338 | } | 339 | } |
339 | 340 | ||
340 | return activityPubResponse(activityPubContextify(object), res) | 341 | return activityPubResponse(activityPubContextify(object, 'CacheFile'), res) |
341 | } | 342 | } |
342 | 343 | ||
343 | async function videoPlaylistController (req: express.Request, res: express.Response) { | 344 | async function videoPlaylistController (req: express.Request, res: express.Response) { |
@@ -353,7 +354,7 @@ async function videoPlaylistController (req: express.Request, res: express.Respo | |||
353 | return activityPubResponse(activityPubContextify(object), res) | 354 | return activityPubResponse(activityPubContextify(object), res) |
354 | } | 355 | } |
355 | 356 | ||
356 | async function videoPlaylistElementController (req: express.Request, res: express.Response) { | 357 | function videoPlaylistElementController (req: express.Request, res: express.Response) { |
357 | const videoPlaylistElement = res.locals.videoPlaylistElementAP | 358 | const videoPlaylistElement = res.locals.videoPlaylistElementAP |
358 | 359 | ||
359 | const json = videoPlaylistElement.toActivityPubObject() | 360 | const json = videoPlaylistElement.toActivityPubObject() |
@@ -386,7 +387,7 @@ async function actorPlaylists (req: express.Request, account: MAccountId) { | |||
386 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) | 387 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
387 | } | 388 | } |
388 | 389 | ||
389 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideo, url: string) { | 390 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideoId, url: string) { |
390 | const handler = async (start: number, count: number) => { | 391 | const handler = async (start: number, count: number) => { |
391 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) | 392 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) |
392 | return { | 393 | return { |
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index ca42106b8..3b8fb34a8 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts | |||
@@ -46,11 +46,15 @@ const inboxQueue = queue<QueueParam, Error>((task, cb) => { | |||
46 | 46 | ||
47 | processActivities(task.activities, options) | 47 | processActivities(task.activities, options) |
48 | .then(() => cb()) | 48 | .then(() => cb()) |
49 | .catch(err => { | ||
50 | logger.error('Error in process activities.', { err }) | ||
51 | cb() | ||
52 | }) | ||
49 | }) | 53 | }) |
50 | 54 | ||
51 | function inboxController (req: express.Request, res: express.Response) { | 55 | function inboxController (req: express.Request, res: express.Response) { |
52 | const rootActivity: RootActivity = req.body | 56 | const rootActivity: RootActivity = req.body |
53 | let activities: Activity[] = [] | 57 | let activities: Activity[] |
54 | 58 | ||
55 | if ([ 'Collection', 'CollectionPage' ].indexOf(rootActivity.type) !== -1) { | 59 | if ([ 'Collection', 'CollectionPage' ].indexOf(rootActivity.type) !== -1) { |
56 | activities = (rootActivity as ActivityPubCollection).items | 60 | activities = (rootActivity as ActivityPubCollection).items |