aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-14 15:01:28 +0100
committerChocobozzz <me@florianbigard.com>2018-11-14 16:32:27 +0100
commit5c6d985faeef1d6793d3f44ca6374f1a9b722806 (patch)
tree567e31a84e721bf762189582f92ac2ec5c402bcc /server/controllers/activitypub
parentdf66d81583e07ce049daeeef1edc6a87b57b3684 (diff)
downloadPeerTube-5c6d985faeef1d6793d3f44ca6374f1a9b722806.tar.gz
PeerTube-5c6d985faeef1d6793d3f44ca6374f1a9b722806.tar.zst
PeerTube-5c6d985faeef1d6793d3f44ca6374f1a9b722806.zip
Check activities host
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts36
-rw-r--r--server/controllers/activitypub/inbox.ts6
2 files changed, 36 insertions, 6 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'
3import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' 3import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' 4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
5import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' 5import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
6import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send' 6import { buildAnnounceWithVideoAudience, buildDislikeActivity, buildLikeActivity } from '../../lib/activitypub/send'
7import { audiencify, getAudience } from '../../lib/activitypub/audience' 7import { audiencify, getAudience } from '../../lib/activitypub/audience'
8import { buildCreateActivity } from '../../lib/activitypub/send/send-create' 8import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
9import { 9import {
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'
16import { videoCommentGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' 17import {
18 getAccountVideoRateValidator,
19 videoCommentGetValidator,
20 videosGetValidator
21} from '../../middlewares/validators'
17import { AccountModel } from '../../models/account/account' 22import { AccountModel } from '../../models/account/account'
18import { ActorModel } from '../../models/activitypub/actor' 23import { ActorModel } from '../../models/activitypub/actor'
19import { ActorFollowModel } from '../../models/activitypub/actor-follow' 24import { ActorFollowModel } from '../../models/activitypub/actor-follow'
@@ -25,6 +30,7 @@ import { cacheRoute } from '../../middlewares/cache'
25import { activityPubResponse } from './utils' 30import { activityPubResponse } from './utils'
26import { AccountVideoRateModel } from '../../models/account/account-video-rate' 31import { AccountVideoRateModel } from '../../models/account/account-video-rate'
27import { 32import {
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)
57activityPubClientRouter.get('/accounts?/:name/likes/:videoId',
58 executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))),
59 executeIfActivityPub(getAccountVideoRate('like'))
60)
61activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId',
62 executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('dislike'))),
63 executeIfActivityPub(getAccountVideoRate('dislike'))
64)
51 65
52activityPubClientRouter.get('/videos/watch/:id', 66activityPubClientRouter.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)
65activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', 79activityPubClientRouter.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
150function 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
136async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { 164async 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)
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index 738d155eb..f0e65015b 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -43,11 +43,13 @@ export {
43// --------------------------------------------------------------------------- 43// ---------------------------------------------------------------------------
44 44
45const inboxQueue = queue<{ activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel }, Error>((task, cb) => { 45const inboxQueue = queue<{ activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel }, Error>((task, cb) => {
46 processActivities(task.activities, task.signatureActor, task.inboxActor) 46 const options = { signatureActor: task.signatureActor, inboxActor: task.inboxActor }
47
48 processActivities(task.activities, options)
47 .then(() => cb()) 49 .then(() => cb())
48}) 50})
49 51
50function inboxController (req: express.Request, res: express.Response, next: express.NextFunction) { 52function inboxController (req: express.Request, res: express.Response) {
51 const rootActivity: RootActivity = req.body 53 const rootActivity: RootActivity = req.body
52 let activities: Activity[] = [] 54 let activities: Activity[] = []
53 55