diff options
Diffstat (limited to 'server/controllers/activitypub/client.ts')
-rw-r--r-- | server/controllers/activitypub/client.ts | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 433186179..ffbf1ba19 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -3,17 +3,22 @@ import * as express from 'express' | |||
3 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' | 3 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' |
4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | 4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
5 | import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' | 5 | import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' |
6 | import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send' | 6 | import { buildAnnounceWithVideoAudience, buildDislikeActivity, buildLikeActivity } from '../../lib/activitypub/send' |
7 | import { audiencify, getAudience } from '../../lib/activitypub/audience' | 7 | import { audiencify, getAudience } from '../../lib/activitypub/audience' |
8 | import { buildCreateActivity } from '../../lib/activitypub/send/send-create' | 8 | import { buildCreateActivity } from '../../lib/activitypub/send/send-create' |
9 | import { | 9 | import { |
10 | asyncMiddleware, | 10 | asyncMiddleware, |
11 | videosShareValidator, | ||
11 | executeIfActivityPub, | 12 | executeIfActivityPub, |
12 | localAccountValidator, | 13 | localAccountValidator, |
13 | localVideoChannelValidator, | 14 | localVideoChannelValidator, |
14 | videosCustomGetValidator | 15 | videosCustomGetValidator |
15 | } from '../../middlewares' | 16 | } from '../../middlewares' |
16 | import { videoCommentGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' | 17 | import { |
18 | getAccountVideoRateValidator, | ||
19 | videoCommentGetValidator, | ||
20 | videosGetValidator | ||
21 | } from '../../middlewares/validators' | ||
17 | import { AccountModel } from '../../models/account/account' | 22 | import { AccountModel } from '../../models/account/account' |
18 | import { ActorModel } from '../../models/activitypub/actor' | 23 | import { ActorModel } from '../../models/activitypub/actor' |
19 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 24 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
@@ -25,6 +30,7 @@ import { cacheRoute } from '../../middlewares/cache' | |||
25 | import { activityPubResponse } from './utils' | 30 | import { activityPubResponse } from './utils' |
26 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 31 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
27 | import { | 32 | import { |
33 | getRateUrl, | ||
28 | getVideoCommentsActivityPubUrl, | 34 | getVideoCommentsActivityPubUrl, |
29 | getVideoDislikesActivityPubUrl, | 35 | getVideoDislikesActivityPubUrl, |
30 | getVideoLikesActivityPubUrl, | 36 | getVideoLikesActivityPubUrl, |
@@ -48,6 +54,14 @@ activityPubClientRouter.get('/accounts?/:name/following', | |||
48 | executeIfActivityPub(asyncMiddleware(localAccountValidator)), | 54 | executeIfActivityPub(asyncMiddleware(localAccountValidator)), |
49 | executeIfActivityPub(asyncMiddleware(accountFollowingController)) | 55 | executeIfActivityPub(asyncMiddleware(accountFollowingController)) |
50 | ) | 56 | ) |
57 | activityPubClientRouter.get('/accounts?/:name/likes/:videoId', | ||
58 | executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))), | ||
59 | executeIfActivityPub(getAccountVideoRate('like')) | ||
60 | ) | ||
61 | activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', | ||
62 | executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('dislike'))), | ||
63 | executeIfActivityPub(getAccountVideoRate('dislike')) | ||
64 | ) | ||
51 | 65 | ||
52 | activityPubClientRouter.get('/videos/watch/:id', | 66 | activityPubClientRouter.get('/videos/watch/:id', |
53 | executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))), | 67 | executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))), |
@@ -62,7 +76,7 @@ activityPubClientRouter.get('/videos/watch/:id/announces', | |||
62 | executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))), | 76 | executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))), |
63 | executeIfActivityPub(asyncMiddleware(videoAnnouncesController)) | 77 | executeIfActivityPub(asyncMiddleware(videoAnnouncesController)) |
64 | ) | 78 | ) |
65 | activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', | 79 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', |
66 | executeIfActivityPub(asyncMiddleware(videosShareValidator)), | 80 | executeIfActivityPub(asyncMiddleware(videosShareValidator)), |
67 | executeIfActivityPub(asyncMiddleware(videoAnnounceController)) | 81 | executeIfActivityPub(asyncMiddleware(videoAnnounceController)) |
68 | ) | 82 | ) |
@@ -133,6 +147,20 @@ async function accountFollowingController (req: express.Request, res: express.Re | |||
133 | return activityPubResponse(activityPubContextify(activityPubResult), res) | 147 | return activityPubResponse(activityPubContextify(activityPubResult), res) |
134 | } | 148 | } |
135 | 149 | ||
150 | function getAccountVideoRate (rateType: VideoRateType) { | ||
151 | return (req: express.Request, res: express.Response) => { | ||
152 | const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate | ||
153 | |||
154 | const byActor = accountVideoRate.Account.Actor | ||
155 | const url = getRateUrl(rateType, byActor, accountVideoRate.Video) | ||
156 | const APObject = rateType === 'like' | ||
157 | ? buildLikeActivity(url, byActor, accountVideoRate.Video) | ||
158 | : buildCreateActivity(url, byActor, buildDislikeActivity(url, byActor, accountVideoRate.Video)) | ||
159 | |||
160 | return activityPubResponse(activityPubContextify(APObject), res) | ||
161 | } | ||
162 | } | ||
163 | |||
136 | async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { | 164 | async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { |
137 | const video: VideoModel = res.locals.video | 165 | const video: VideoModel = res.locals.video |
138 | 166 | ||
@@ -276,7 +304,7 @@ function videoRates (req: express.Request, rateType: VideoRateType, video: Video | |||
276 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) | 304 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) |
277 | return { | 305 | return { |
278 | total: result.count, | 306 | total: result.count, |
279 | data: result.rows.map(r => r.Account.Actor.url) | 307 | data: result.rows.map(r => r.url) |
280 | } | 308 | } |
281 | } | 309 | } |
282 | return activityPubCollectionPagination(url, handler, req.query.page) | 310 | return activityPubCollectionPagination(url, handler, req.query.page) |