From 09979f8959425390b879bce22101a9bc061ae9a0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 5 Mar 2019 11:30:43 +0100 Subject: Refactor video playlist middlewares --- server/controllers/api/video-playlist.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'server/controllers/api/video-playlist.ts') 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 { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, - commonVideosFiltersValidator, optionalAuthenticate, + commonVideosFiltersValidator, + optionalAuthenticate, paginationValidator, setDefaultPagination, setDefaultSort @@ -31,15 +32,8 @@ import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/vid import { processImage } from '../../helpers/image-utils' import { join } from 'path' import { UserModel } from '../../models/account/user' -import { - sendCreateVideoPlaylist, - sendDeleteVideoPlaylist, - sendUpdateVideoPlaylist -} from '../../lib/activitypub/send' -import { - getVideoPlaylistActivityPubUrl, - getVideoPlaylistElementActivityPubUrl -} from '../../lib/activitypub/url' +import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send' +import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url' import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' import { VideoModel } from '../../models/video/video' import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' @@ -233,8 +227,6 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response) } const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) - // We need more attributes for the federation - playlistUpdated.OwnerAccount = await AccountModel.load(playlistUpdated.OwnerAccount.id, t) const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE @@ -305,8 +297,6 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response) } } - // We need more attributes for the federation - videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t) await sendUpdateVideoPlaylist(videoPlaylist, t) return playlistElement @@ -332,8 +322,6 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re const element = await videoPlaylistElement.save({ transaction: t }) - // We need more attributes for the federation - videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t) await sendUpdateVideoPlaylist(videoPlaylist, t) return element @@ -355,8 +343,6 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo // Decrease position of the next elements await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t) - // We need more attributes for the federation - videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t) await sendUpdateVideoPlaylist(videoPlaylist, t) 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 // Decrease positions of elements after the old position of our ordered elements (decrease) await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t) - // We need more attributes for the federation - videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t) await sendUpdateVideoPlaylist(videoPlaylist, t) }) -- cgit v1.2.3