aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-05 11:30:43 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commit09979f8959425390b879bce22101a9bc061ae9a0 (patch)
treea128a50b7c58c070e4b7af44028dfaa03e2d2ef1 /server/controllers/api
parentdf0b219d36bf6852cdf2a7ad09ed4a41c6bccefa (diff)
downloadPeerTube-09979f8959425390b879bce22101a9bc061ae9a0.tar.gz
PeerTube-09979f8959425390b879bce22101a9bc061ae9a0.tar.zst
PeerTube-09979f8959425390b879bce22101a9bc061ae9a0.zip
Refactor video playlist middlewares
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/video-playlist.ts24
1 files changed, 4 insertions, 20 deletions
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 8605f3dfc..2700e8dc7 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -4,7 +4,8 @@ import {
4 asyncMiddleware, 4 asyncMiddleware,
5 asyncRetryTransactionMiddleware, 5 asyncRetryTransactionMiddleware,
6 authenticate, 6 authenticate,
7 commonVideosFiltersValidator, optionalAuthenticate, 7 commonVideosFiltersValidator,
8 optionalAuthenticate,
8 paginationValidator, 9 paginationValidator,
9 setDefaultPagination, 10 setDefaultPagination,
10 setDefaultSort 11 setDefaultSort
@@ -31,15 +32,8 @@ import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/vid
31import { processImage } from '../../helpers/image-utils' 32import { processImage } from '../../helpers/image-utils'
32import { join } from 'path' 33import { join } from 'path'
33import { UserModel } from '../../models/account/user' 34import { UserModel } from '../../models/account/user'
34import { 35import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'
35 sendCreateVideoPlaylist, 36import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'
36 sendDeleteVideoPlaylist,
37 sendUpdateVideoPlaylist
38} from '../../lib/activitypub/send'
39import {
40 getVideoPlaylistActivityPubUrl,
41 getVideoPlaylistElementActivityPubUrl
42} from '../../lib/activitypub/url'
43import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' 37import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
44import { VideoModel } from '../../models/video/video' 38import { VideoModel } from '../../models/video/video'
45import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' 39import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
@@ -233,8 +227,6 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
233 } 227 }
234 228
235 const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) 229 const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions)
236 // We need more attributes for the federation
237 playlistUpdated.OwnerAccount = await AccountModel.load(playlistUpdated.OwnerAccount.id, t)
238 230
239 const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE 231 const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE
240 232
@@ -305,8 +297,6 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
305 } 297 }
306 } 298 }
307 299
308 // We need more attributes for the federation
309 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
310 await sendUpdateVideoPlaylist(videoPlaylist, t) 300 await sendUpdateVideoPlaylist(videoPlaylist, t)
311 301
312 return playlistElement 302 return playlistElement
@@ -332,8 +322,6 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
332 322
333 const element = await videoPlaylistElement.save({ transaction: t }) 323 const element = await videoPlaylistElement.save({ transaction: t })
334 324
335 // We need more attributes for the federation
336 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
337 await sendUpdateVideoPlaylist(videoPlaylist, t) 325 await sendUpdateVideoPlaylist(videoPlaylist, t)
338 326
339 return element 327 return element
@@ -355,8 +343,6 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
355 // Decrease position of the next elements 343 // Decrease position of the next elements
356 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t) 344 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t)
357 345
358 // We need more attributes for the federation
359 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
360 await sendUpdateVideoPlaylist(videoPlaylist, t) 346 await sendUpdateVideoPlaylist(videoPlaylist, t)
361 347
362 logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid) 348 logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid)
@@ -398,8 +384,6 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
398 // Decrease positions of elements after the old position of our ordered elements (decrease) 384 // Decrease positions of elements after the old position of our ordered elements (decrease)
399 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t) 385 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t)
400 386
401 // We need more attributes for the federation
402 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
403 await sendUpdateVideoPlaylist(videoPlaylist, t) 387 await sendUpdateVideoPlaylist(videoPlaylist, t)
404 }) 388 })
405 389