From 0f320037e689b2778959c12ddd4ce790f6e4ae4f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 May 2018 15:10:13 +0200 Subject: Add ability to update a video channel --- server/controllers/api/videos/index.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 4b3198a74..c07430e6c 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -19,7 +19,12 @@ import { VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers' -import { fetchRemoteVideoDescription, getVideoActivityPubUrl, shareVideoByServerAndChannel } from '../../../lib/activitypub' +import { + changeVideoChannelShare, + fetchRemoteVideoDescription, + getVideoActivityPubUrl, + shareVideoByServerAndChannel +} from '../../../lib/activitypub' import { sendCreateVideo, sendCreateView, sendUpdateVideo } from '../../../lib/activitypub/send' import { JobQueue } from '../../../lib/job-queue' import { Redis } from '../../../lib/redis' @@ -305,6 +310,7 @@ async function updateVideo (req: express.Request, res: express.Response) { const sequelizeOptions = { transaction: t } + const oldVideoChannel = videoInstance.VideoChannel if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name) if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category) @@ -325,18 +331,25 @@ async function updateVideo (req: express.Request, res: express.Response) { const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) + // Video tags update? if (videoInfoToUpdate.tags) { const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) - await videoInstance.$set('Tags', tagInstances, sequelizeOptions) - videoInstance.Tags = tagInstances + await videoInstanceUpdated.$set('Tags', tagInstances, sequelizeOptions) + videoInstanceUpdated.Tags = tagInstances } - // Now we'll update the video's meta data to our friends - if (wasPrivateVideo === false) { - await sendUpdateVideo(videoInstanceUpdated, t) + // Video channel update? + if (res.locals.videoChannel && videoInstanceUpdated.channelId !== res.locals.videoChannel.id) { + await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel) + videoInstance.VideoChannel = res.locals.videoChannel + + if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t) } + // Now we'll update the video's meta data to our friends + if (wasPrivateVideo === false) await sendUpdateVideo(videoInstanceUpdated, t) + // Video is not private anymore, send a create action to remote servers if (wasPrivateVideo === true && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE) { await sendCreateVideo(videoInstanceUpdated, t) -- cgit v1.2.3