+async function updateVideo (req: express.Request, res: express.Response) {
+ const videoInstance = res.locals.video
+ const videoFieldsSave = videoInstance.toJSON()
+ const oldVideoAuditView = new VideoAuditView(videoInstance.toFormattedDetailsJSON())
+ const videoInfoToUpdate: VideoUpdate = req.body
+
+ const wasPrivateVideo = videoInstance.privacy === VideoPrivacy.PRIVATE
+ const wasNotPrivateVideo = videoInstance.privacy !== VideoPrivacy.PRIVATE
+ const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED
+
+ // Process thumbnail or create it from the video
+ const thumbnailModel = req.files && req.files['thumbnailfile']
+ ? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE)
+ : undefined
+
+ const previewModel = req.files && req.files['previewfile']
+ ? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW)
+ : undefined
+
+ try {
+ const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => {
+ 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)
+ if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
+ if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
+ if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
+ if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.set('waitTranscoding', videoInfoToUpdate.waitTranscoding)
+ if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
+ if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
+ if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
+ if (videoInfoToUpdate.downloadEnabled !== undefined) videoInstance.set('downloadEnabled', videoInfoToUpdate.downloadEnabled)
+
+ if (videoInfoToUpdate.originallyPublishedAt !== undefined && videoInfoToUpdate.originallyPublishedAt !== null) {
+ videoInstance.originallyPublishedAt = new Date(videoInfoToUpdate.originallyPublishedAt)
+ }
+
+ if (videoInfoToUpdate.privacy !== undefined) {
+ const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
+ videoInstance.privacy = newPrivacy
+
+ // The video was private, and is not anymore -> publish it
+ if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
+ videoInstance.publishedAt = new Date()