aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-19 10:35:15 +0100
committerChocobozzz <me@florianbigard.com>2019-03-19 10:35:15 +0100
commitdae86118ed5d4026d04acb9d0e36829b9ad8eb4e (patch)
treea5bf9c4487240bf75a9b328cad459a0587f90dea /server/controllers/activitypub
parente65c0c5b1fab9c3d93f51721b2458cf5cf471f20 (diff)
downloadPeerTube-dae86118ed5d4026d04acb9d0e36829b9ad8eb4e.tar.gz
PeerTube-dae86118ed5d4026d04acb9d0e36829b9ad8eb4e.tar.zst
PeerTube-dae86118ed5d4026d04acb9d0e36829b9ad8eb4e.zip
Cleanup express locals typings
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts36
-rw-r--r--server/controllers/activitypub/inbox.ts9
-rw-r--r--server/controllers/activitypub/outbox.ts2
3 files changed, 20 insertions, 27 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index cc2671fc1..e06aa35f4 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -169,27 +169,27 @@ export {
169// --------------------------------------------------------------------------- 169// ---------------------------------------------------------------------------
170 170
171function accountController (req: express.Request, res: express.Response) { 171function accountController (req: express.Request, res: express.Response) {
172 const account: AccountModel = res.locals.account 172 const account = res.locals.account
173 173
174 return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res) 174 return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res)
175} 175}
176 176
177async function accountFollowersController (req: express.Request, res: express.Response) { 177async function accountFollowersController (req: express.Request, res: express.Response) {
178 const account: AccountModel = res.locals.account 178 const account = res.locals.account
179 const activityPubResult = await actorFollowers(req, account.Actor) 179 const activityPubResult = await actorFollowers(req, account.Actor)
180 180
181 return activityPubResponse(activityPubContextify(activityPubResult), res) 181 return activityPubResponse(activityPubContextify(activityPubResult), res)
182} 182}
183 183
184async function accountFollowingController (req: express.Request, res: express.Response) { 184async function accountFollowingController (req: express.Request, res: express.Response) {
185 const account: AccountModel = res.locals.account 185 const account = res.locals.account
186 const activityPubResult = await actorFollowing(req, account.Actor) 186 const activityPubResult = await actorFollowing(req, account.Actor)
187 187
188 return activityPubResponse(activityPubContextify(activityPubResult), res) 188 return activityPubResponse(activityPubContextify(activityPubResult), res)
189} 189}
190 190
191async function accountPlaylistsController (req: express.Request, res: express.Response) { 191async function accountPlaylistsController (req: express.Request, res: express.Response) {
192 const account: AccountModel = res.locals.account 192 const account = res.locals.account
193 const activityPubResult = await actorPlaylists(req, account) 193 const activityPubResult = await actorPlaylists(req, account)
194 194
195 return activityPubResponse(activityPubContextify(activityPubResult), res) 195 return activityPubResponse(activityPubContextify(activityPubResult), res)
@@ -197,7 +197,7 @@ async function accountPlaylistsController (req: express.Request, res: express.Re
197 197
198function getAccountVideoRate (rateType: VideoRateType) { 198function getAccountVideoRate (rateType: VideoRateType) {
199 return (req: express.Request, res: express.Response) => { 199 return (req: express.Request, res: express.Response) => {
200 const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate 200 const accountVideoRate = res.locals.accountVideoRate
201 201
202 const byActor = accountVideoRate.Account.Actor 202 const byActor = accountVideoRate.Account.Actor
203 const url = getRateUrl(rateType, byActor, accountVideoRate.Video) 203 const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
@@ -211,7 +211,7 @@ function getAccountVideoRate (rateType: VideoRateType) {
211 211
212async function videoController (req: express.Request, res: express.Response) { 212async function videoController (req: express.Request, res: express.Response) {
213 // We need more attributes 213 // We need more attributes
214 const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id) 214 const video = await VideoModel.loadForGetAPI(res.locals.video.id)
215 215
216 if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url) 216 if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url)
217 217
@@ -230,7 +230,7 @@ async function videoController (req: express.Request, res: express.Response) {
230} 230}
231 231
232async function videoAnnounceController (req: express.Request, res: express.Response) { 232async function videoAnnounceController (req: express.Request, res: express.Response) {
233 const share = res.locals.videoShare as VideoShareModel 233 const share = res.locals.videoShare
234 234
235 if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url) 235 if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url)
236 236
@@ -240,7 +240,7 @@ async function videoAnnounceController (req: express.Request, res: express.Respo
240} 240}
241 241
242async function videoAnnouncesController (req: express.Request, res: express.Response) { 242async function videoAnnouncesController (req: express.Request, res: express.Response) {
243 const video: VideoModel = res.locals.video 243 const video = res.locals.video
244 244
245 const handler = async (start: number, count: number) => { 245 const handler = async (start: number, count: number) => {
246 const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) 246 const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count)
@@ -255,21 +255,21 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp
255} 255}
256 256
257async function videoLikesController (req: express.Request, res: express.Response) { 257async function videoLikesController (req: express.Request, res: express.Response) {
258 const video: VideoModel = res.locals.video 258 const video = res.locals.video
259 const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) 259 const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video))
260 260
261 return activityPubResponse(activityPubContextify(json), res) 261 return activityPubResponse(activityPubContextify(json), res)
262} 262}
263 263
264async function videoDislikesController (req: express.Request, res: express.Response) { 264async function videoDislikesController (req: express.Request, res: express.Response) {
265 const video: VideoModel = res.locals.video 265 const video = res.locals.video
266 const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) 266 const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video))
267 267
268 return activityPubResponse(activityPubContextify(json), res) 268 return activityPubResponse(activityPubContextify(json), res)
269} 269}
270 270
271async function videoCommentsController (req: express.Request, res: express.Response) { 271async function videoCommentsController (req: express.Request, res: express.Response) {
272 const video: VideoModel = res.locals.video 272 const video = res.locals.video
273 273
274 const handler = async (start: number, count: number) => { 274 const handler = async (start: number, count: number) => {
275 const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) 275 const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count)
@@ -284,27 +284,27 @@ async function videoCommentsController (req: express.Request, res: express.Respo
284} 284}
285 285
286async function videoChannelController (req: express.Request, res: express.Response) { 286async function videoChannelController (req: express.Request, res: express.Response) {
287 const videoChannel: VideoChannelModel = res.locals.videoChannel 287 const videoChannel = res.locals.videoChannel
288 288
289 return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) 289 return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res)
290} 290}
291 291
292async function videoChannelFollowersController (req: express.Request, res: express.Response) { 292async function videoChannelFollowersController (req: express.Request, res: express.Response) {
293 const videoChannel: VideoChannelModel = res.locals.videoChannel 293 const videoChannel = res.locals.videoChannel
294 const activityPubResult = await actorFollowers(req, videoChannel.Actor) 294 const activityPubResult = await actorFollowers(req, videoChannel.Actor)
295 295
296 return activityPubResponse(activityPubContextify(activityPubResult), res) 296 return activityPubResponse(activityPubContextify(activityPubResult), res)
297} 297}
298 298
299async function videoChannelFollowingController (req: express.Request, res: express.Response) { 299async function videoChannelFollowingController (req: express.Request, res: express.Response) {
300 const videoChannel: VideoChannelModel = res.locals.videoChannel 300 const videoChannel = res.locals.videoChannel
301 const activityPubResult = await actorFollowing(req, videoChannel.Actor) 301 const activityPubResult = await actorFollowing(req, videoChannel.Actor)
302 302
303 return activityPubResponse(activityPubContextify(activityPubResult), res) 303 return activityPubResponse(activityPubContextify(activityPubResult), res)
304} 304}
305 305
306async function videoCommentController (req: express.Request, res: express.Response) { 306async function videoCommentController (req: express.Request, res: express.Response) {
307 const videoComment: VideoCommentModel = res.locals.videoComment 307 const videoComment = res.locals.videoComment
308 308
309 if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url) 309 if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url)
310 310
@@ -323,7 +323,7 @@ async function videoCommentController (req: express.Request, res: express.Respon
323} 323}
324 324
325async function videoRedundancyController (req: express.Request, res: express.Response) { 325async function videoRedundancyController (req: express.Request, res: express.Response) {
326 const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy 326 const videoRedundancy = res.locals.videoRedundancy
327 if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url) 327 if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)
328 328
329 const serverActor = await getServerActor() 329 const serverActor = await getServerActor()
@@ -340,7 +340,7 @@ async function videoRedundancyController (req: express.Request, res: express.Res
340} 340}
341 341
342async function videoPlaylistController (req: express.Request, res: express.Response) { 342async function videoPlaylistController (req: express.Request, res: express.Response) {
343 const playlist: VideoPlaylistModel = res.locals.videoPlaylist 343 const playlist = res.locals.videoPlaylist
344 344
345 // We need more attributes 345 // We need more attributes
346 playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId) 346 playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId)
@@ -353,7 +353,7 @@ async function videoPlaylistController (req: express.Request, res: express.Respo
353} 353}
354 354
355async function videoPlaylistElementController (req: express.Request, res: express.Response) { 355async function videoPlaylistElementController (req: express.Request, res: express.Response) {
356 const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement 356 const videoPlaylistElement = res.locals.videoPlaylistElement
357 357
358 const json = videoPlaylistElement.toActivityPubObject() 358 const json = videoPlaylistElement.toActivityPubObject()
359 return activityPubResponse(activityPubContextify(json), res) 359 return activityPubResponse(activityPubContextify(json), res)
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index f0e65015b..38d5c51df 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -5,8 +5,6 @@ import { logger } from '../../helpers/logger'
5import { processActivities } from '../../lib/activitypub/process/process' 5import { processActivities } from '../../lib/activitypub/process/process'
6import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares' 6import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'
7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
8import { VideoChannelModel } from '../../models/video/video-channel'
9import { AccountModel } from '../../models/account/account'
10import { queue } from 'async' 8import { queue } from 'async'
11import { ActorModel } from '../../models/activitypub/actor' 9import { ActorModel } from '../../models/activitypub/actor'
12 10
@@ -66,12 +64,7 @@ function inboxController (req: express.Request, res: express.Response) {
66 activities = activities.filter(a => isActivityValid(a)) 64 activities = activities.filter(a => isActivityValid(a))
67 logger.debug('We keep %d activities.', activities.length, { activities }) 65 logger.debug('We keep %d activities.', activities.length, { activities })
68 66
69 let accountOrChannel: VideoChannelModel | AccountModel 67 const accountOrChannel = res.locals.account || res.locals.videoChannel
70 if (res.locals.account) {
71 accountOrChannel = res.locals.account
72 } else if (res.locals.videoChannel) {
73 accountOrChannel = res.locals.videoChannel
74 }
75 68
76 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url) 69 logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
77 70
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index e060affb2..38b6ec976 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -33,7 +33,7 @@ export {
33// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
34 34
35async function outboxController (req: express.Request, res: express.Response) { 35async function outboxController (req: express.Request, res: express.Response) {
36 const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel 36 const accountOrVideoChannel = res.locals.account || res.locals.videoChannel
37 const actor = accountOrVideoChannel.Actor 37 const actor = accountOrVideoChannel.Actor
38 const actorOutboxUrl = actor.url + '/outbox' 38 const actorOutboxUrl = actor.url + '/outbox'
39 39