+ const videoChannel = video.VideoChannel
+ if (videoChannel.Account.id !== account.id) {
+ throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url)
+ }
+
+ const to = overrideTo ? overrideTo : videoObject.to
+ const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, to)
+ video.name = videoData.name
+ video.uuid = videoData.uuid
+ video.url = videoData.url
+ video.category = videoData.category
+ video.licence = videoData.licence
+ video.language = videoData.language
+ video.description = videoData.description
+ video.support = videoData.support
+ video.nsfw = videoData.nsfw
+ video.commentsEnabled = videoData.commentsEnabled
+ video.downloadEnabled = videoData.downloadEnabled
+ video.waitTranscoding = videoData.waitTranscoding
+ video.state = videoData.state
+ video.duration = videoData.duration
+ video.createdAt = videoData.createdAt
+ video.publishedAt = videoData.publishedAt
+ video.originallyPublishedAt = videoData.originallyPublishedAt
+ video.privacy = videoData.privacy
+ video.channelId = videoData.channelId
+ video.views = videoData.views
+
+ const videoUpdated = await video.save(sequelizeOptions) as MVideoFullLight
+
+ if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t)
+
+ // FIXME: use icon URL instead
+ const previewUrl = buildRemoteBaseUrl(videoUpdated, join(STATIC_PATHS.PREVIEWS, videoUpdated.getPreview().filename))
+ const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
+ await videoUpdated.addAndSaveThumbnail(previewModel, t)
+
+ {
+ const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoUpdated, videoObject)
+ const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a))
+
+ // Remove video files that do not exist anymore
+ const destroyTasks = videoUpdated.VideoFiles
+ .filter(f => !newVideoFiles.find(newFile => newFile.hasSameUniqueKeysThan(f)))
+ .map(f => f.destroy(sequelizeOptions))
+ await Promise.all(destroyTasks)
+
+ // Update or add other one
+ const upsertTasks = videoFileAttributes.map(a => {
+ return VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t })
+ .then(([ file ]) => file)
+ })
+
+ videoUpdated.VideoFiles = await Promise.all(upsertTasks)
+ }
+
+ {
+ const streamingPlaylistAttributes = streamingPlaylistActivityUrlToDBAttributes(videoUpdated, videoObject, videoUpdated.VideoFiles)
+ const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a))
+
+ // Remove video files that do not exist anymore
+ const destroyTasks = videoUpdated.VideoStreamingPlaylists
+ .filter(f => !newStreamingPlaylists.find(newPlaylist => newPlaylist.hasSameUniqueKeysThan(f)))
+ .map(f => f.destroy(sequelizeOptions))
+ await Promise.all(destroyTasks)
+
+ // Update or add other one
+ const upsertTasks = streamingPlaylistAttributes.map(a => {
+ return VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t })
+ .then(([ streamingPlaylist ]) => streamingPlaylist)
+ })
+
+ videoUpdated.VideoStreamingPlaylists = await Promise.all(upsertTasks)