diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-26 11:44:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-26 11:44:08 +0100 |
commit | d6e99e5322209a692cc3d870ddb5dcedbda69f2a (patch) | |
tree | ffb05860149ddb12140d9fdfa0740d3e03d1ed4e /server/controllers/activitypub | |
parent | 66ee325f573feeb61bc6c945151bf64dec6b9698 (diff) | |
download | PeerTube-d6e99e5322209a692cc3d870ddb5dcedbda69f2a.tar.gz PeerTube-d6e99e5322209a692cc3d870ddb5dcedbda69f2a.tar.zst PeerTube-d6e99e5322209a692cc3d870ddb5dcedbda69f2a.zip |
Add context on activitypub responses
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index ba659984f..2587ee212 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | // Intercept ActivityPub client requests | 1 | // Intercept ActivityPub client requests |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { VideoPrivacy } from '../../../shared/models/videos' | 3 | import { VideoPrivacy } from '../../../shared/models/videos' |
4 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
5 | import { pageToStartAndCount } from '../../helpers/core-utils' | 5 | import { pageToStartAndCount } from '../../helpers/core-utils' |
6 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' | 6 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' |
7 | import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' | 7 | import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' |
@@ -69,7 +69,7 @@ export { | |||
69 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { | 69 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { |
70 | const account: AccountModel = res.locals.account | 70 | const account: AccountModel = res.locals.account |
71 | 71 | ||
72 | return res.json(account.toActivityPubObject()) | 72 | return res.json(activityPubContextify(account.toActivityPubObject())) |
73 | .end() | 73 | .end() |
74 | } | 74 | } |
75 | 75 | ||
@@ -77,14 +77,14 @@ async function accountFollowersController (req: express.Request, res: express.Re | |||
77 | const account: AccountModel = res.locals.account | 77 | const account: AccountModel = res.locals.account |
78 | const activityPubResult = await actorFollowers(req, account.Actor) | 78 | const activityPubResult = await actorFollowers(req, account.Actor) |
79 | 79 | ||
80 | return res.json(activityPubResult) | 80 | return res.json(activityPubContextify(activityPubResult)) |
81 | } | 81 | } |
82 | 82 | ||
83 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { | 83 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { |
84 | const account: AccountModel = res.locals.account | 84 | const account: AccountModel = res.locals.account |
85 | const activityPubResult = await actorFollowing(req, account.Actor) | 85 | const activityPubResult = await actorFollowing(req, account.Actor) |
86 | 86 | ||
87 | return res.json(activityPubResult) | 87 | return res.json(activityPubContextify(activityPubResult)) |
88 | } | 88 | } |
89 | 89 | ||
90 | async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -93,42 +93,48 @@ async function videoController (req: express.Request, res: express.Response, nex | |||
93 | // We need more attributes | 93 | // We need more attributes |
94 | const videoAll = await VideoModel.loadAndPopulateAll(video.id) | 94 | const videoAll = await VideoModel.loadAndPopulateAll(video.id) |
95 | const audience = await getAudience(video.VideoChannel.Account.Actor, undefined, video.privacy === VideoPrivacy.PUBLIC) | 95 | const audience = await getAudience(video.VideoChannel.Account.Actor, undefined, video.privacy === VideoPrivacy.PUBLIC) |
96 | const videoObject = audiencify(videoAll.toActivityPubObject(), audience) | ||
96 | 97 | ||
97 | return res.json(audiencify(videoAll.toActivityPubObject(), audience)) | 98 | return res.json(activityPubContextify(videoObject)) |
98 | } | 99 | } |
99 | 100 | ||
100 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 101 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
101 | const share = res.locals.videoShare as VideoShareModel | 102 | const share = res.locals.videoShare as VideoShareModel |
102 | const object = await buildVideoAnnounceToFollowers(share.Actor, res.locals.video, undefined) | 103 | const object = await buildVideoAnnounceToFollowers(share.Actor, res.locals.video, undefined) |
103 | 104 | ||
104 | return res.json(object) | 105 | return res.json(activityPubContextify(object)) |
105 | } | 106 | } |
106 | 107 | ||
107 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { | 108 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { |
108 | const videoChannel: VideoChannelModel = res.locals.videoChannel | 109 | const videoChannel: VideoChannelModel = res.locals.videoChannel |
109 | 110 | ||
110 | return res.json(videoChannel.toActivityPubObject()) | 111 | return res.json(activityPubContextify(videoChannel.toActivityPubObject())) |
111 | } | 112 | } |
112 | 113 | ||
113 | async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { | 114 | async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { |
114 | const videoChannel: VideoChannelModel = res.locals.videoChannel | 115 | const videoChannel: VideoChannelModel = res.locals.videoChannel |
115 | const activityPubResult = await actorFollowers(req, videoChannel.Actor) | 116 | const activityPubResult = await actorFollowers(req, videoChannel.Actor) |
116 | 117 | ||
117 | return res.json(activityPubResult) | 118 | return res.json(activityPubContextify(activityPubResult)) |
118 | } | 119 | } |
119 | 120 | ||
120 | async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { | 121 | async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { |
121 | const videoChannel: VideoChannelModel = res.locals.videoChannel | 122 | const videoChannel: VideoChannelModel = res.locals.videoChannel |
122 | const activityPubResult = await actorFollowing(req, videoChannel.Actor) | 123 | const activityPubResult = await actorFollowing(req, videoChannel.Actor) |
123 | 124 | ||
124 | return res.json(activityPubResult) | 125 | return res.json(activityPubContextify(activityPubResult)) |
125 | } | 126 | } |
126 | 127 | ||
127 | async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { | 128 | async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { |
128 | const videoComment: VideoCommentModel = res.locals.videoComment | 129 | const videoComment: VideoCommentModel = res.locals.videoComment |
129 | 130 | ||
130 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) | 131 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) |
131 | return res.json(videoComment.toActivityPubObject(threadParentComments)) | 132 | const isPublic = true // Comments are always public |
133 | const audience = await getAudience(videoComment.Account.Actor, undefined, isPublic) | ||
134 | |||
135 | const videoCommentObject = audiencify(videoComment.toActivityPubObject(threadParentComments), audience) | ||
136 | |||
137 | return res.json(activityPubContextify(videoCommentObject)) | ||
132 | } | 138 | } |
133 | 139 | ||
134 | // --------------------------------------------------------------------------- | 140 | // --------------------------------------------------------------------------- |