aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/client.ts37
1 files changed, 21 insertions, 16 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 8e295b4f9..f5ac9c466 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -94,22 +94,21 @@ export {
94function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { 94function accountController (req: express.Request, res: express.Response, next: express.NextFunction) {
95 const account: AccountModel = res.locals.account 95 const account: AccountModel = res.locals.account
96 96
97 return res.json(activityPubContextify(account.toActivityPubObject())) 97 return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res)
98 .end()
99} 98}
100 99
101async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { 100async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
102 const account: AccountModel = res.locals.account 101 const account: AccountModel = res.locals.account
103 const activityPubResult = await actorFollowers(req, account.Actor) 102 const activityPubResult = await actorFollowers(req, account.Actor)
104 103
105 return res.json(activityPubContextify(activityPubResult)) 104 return activityPubResponse(activityPubContextify(activityPubResult), res)
106} 105}
107 106
108async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { 107async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
109 const account: AccountModel = res.locals.account 108 const account: AccountModel = res.locals.account
110 const activityPubResult = await actorFollowing(req, account.Actor) 109 const activityPubResult = await actorFollowing(req, account.Actor)
111 110
112 return res.json(activityPubContextify(activityPubResult)) 111 return activityPubResponse(activityPubContextify(activityPubResult), res)
113} 112}
114 113
115async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { 114async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -122,17 +121,17 @@ async function videoController (req: express.Request, res: express.Response, nex
122 121
123 if (req.path.endsWith('/activity')) { 122 if (req.path.endsWith('/activity')) {
124 const data = await createActivityData(video.url, video.VideoChannel.Account.Actor, videoObject, undefined, audience) 123 const data = await createActivityData(video.url, video.VideoChannel.Account.Actor, videoObject, undefined, audience)
125 return res.json(activityPubContextify(data)) 124 return activityPubResponse(activityPubContextify(data), res)
126 } 125 }
127 126
128 return res.json(activityPubContextify(videoObject)) 127 return activityPubResponse(activityPubContextify(videoObject), res)
129} 128}
130 129
131async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 130async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
132 const share = res.locals.videoShare as VideoShareModel 131 const share = res.locals.videoShare as VideoShareModel
133 const object = await buildVideoAnnounce(share.Actor, share, res.locals.video, undefined) 132 const object = await buildVideoAnnounce(share.Actor, share, res.locals.video, undefined)
134 133
135 return res.json(activityPubContextify(object)) 134 return activityPubResponse(activityPubContextify(object), res)
136} 135}
137 136
138async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) { 137async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -142,7 +141,7 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp
142 const videoAll = await VideoModel.loadAndPopulateAll(video.id) 141 const videoAll = await VideoModel.loadAndPopulateAll(video.id)
143 const object = videoAll.toAnnouncesActivityPubObject() 142 const object = videoAll.toAnnouncesActivityPubObject()
144 143
145 return res.json(activityPubContextify(object)) 144 return activityPubResponse(activityPubContextify(object), res)
146} 145}
147 146
148async function videoLikesController (req: express.Request, res: express.Response, next: express.NextFunction) { 147async function videoLikesController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -152,7 +151,7 @@ async function videoLikesController (req: express.Request, res: express.Response
152 const videoAll = await VideoModel.loadAndPopulateAll(video.id) 151 const videoAll = await VideoModel.loadAndPopulateAll(video.id)
153 const { likesObject } = videoAll.toRatesActivityPubObjects() 152 const { likesObject } = videoAll.toRatesActivityPubObjects()
154 153
155 return res.json(activityPubContextify(likesObject)) 154 return activityPubResponse(activityPubContextify(likesObject), res)
156} 155}
157 156
158async function videoDislikesController (req: express.Request, res: express.Response, next: express.NextFunction) { 157async function videoDislikesController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -162,7 +161,7 @@ async function videoDislikesController (req: express.Request, res: express.Respo
162 const videoAll = await VideoModel.loadAndPopulateAll(video.id) 161 const videoAll = await VideoModel.loadAndPopulateAll(video.id)
163 const { dislikesObject } = videoAll.toRatesActivityPubObjects() 162 const { dislikesObject } = videoAll.toRatesActivityPubObjects()
164 163
165 return res.json(activityPubContextify(dislikesObject)) 164 return activityPubResponse(activityPubContextify(dislikesObject), res)
166} 165}
167 166
168async function videoCommentsController (req: express.Request, res: express.Response, next: express.NextFunction) { 167async function videoCommentsController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -172,27 +171,27 @@ async function videoCommentsController (req: express.Request, res: express.Respo
172 const videoAll = await VideoModel.loadAndPopulateAll(video.id) 171 const videoAll = await VideoModel.loadAndPopulateAll(video.id)
173 const commentsObject = videoAll.toCommentsActivityPubObject() 172 const commentsObject = videoAll.toCommentsActivityPubObject()
174 173
175 return res.json(activityPubContextify(commentsObject)) 174 return activityPubResponse(activityPubContextify(commentsObject), res)
176} 175}
177 176
178async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { 177async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) {
179 const videoChannel: VideoChannelModel = res.locals.videoChannel 178 const videoChannel: VideoChannelModel = res.locals.videoChannel
180 179
181 return res.json(activityPubContextify(videoChannel.toActivityPubObject())) 180 return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)
182} 181}
183 182
184async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { 183async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
185 const videoChannel: VideoChannelModel = res.locals.videoChannel 184 const videoChannel: VideoChannelModel = res.locals.videoChannel
186 const activityPubResult = await actorFollowers(req, videoChannel.Actor) 185 const activityPubResult = await actorFollowers(req, videoChannel.Actor)
187 186
188 return res.json(activityPubContextify(activityPubResult)) 187 return activityPubResponse(activityPubContextify(activityPubResult), res)
189} 188}
190 189
191async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { 190async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
192 const videoChannel: VideoChannelModel = res.locals.videoChannel 191 const videoChannel: VideoChannelModel = res.locals.videoChannel
193 const activityPubResult = await actorFollowing(req, videoChannel.Actor) 192 const activityPubResult = await actorFollowing(req, videoChannel.Actor)
194 193
195 return res.json(activityPubContextify(activityPubResult)) 194 return activityPubResponse(activityPubContextify(activityPubResult), res)
196} 195}
197 196
198async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { 197async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -206,10 +205,10 @@ async function videoCommentController (req: express.Request, res: express.Respon
206 205
207 if (req.path.endsWith('/activity')) { 206 if (req.path.endsWith('/activity')) {
208 const data = await createActivityData(videoComment.url, videoComment.Account.Actor, videoCommentObject, undefined, audience) 207 const data = await createActivityData(videoComment.url, videoComment.Account.Actor, videoCommentObject, undefined, audience)
209 return res.json(activityPubContextify(data)) 208 return activityPubResponse(activityPubContextify(data), res)
210 } 209 }
211 210
212 return res.json(activityPubContextify(videoCommentObject)) 211 return activityPubResponse(activityPubContextify(videoCommentObject), res)
213} 212}
214 213
215// --------------------------------------------------------------------------- 214// ---------------------------------------------------------------------------
@@ -229,3 +228,9 @@ async function actorFollowers (req: express.Request, actor: ActorModel) {
229 const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count) 228 const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count)
230 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) 229 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
231} 230}
231
232function activityPubResponse (data: any, res: express.Response) {
233 return res.type('application/activity+json; charset=utf-8')
234 .json(data)
235 .end()
236}