- const to = options.overrideTo ? options.overrideTo : options.videoObject.to
- const videoData = await videoActivityObjectToDBAttributes(options.channel, options.videoObject, to)
- options.video.set('name', videoData.name)
- options.video.set('uuid', videoData.uuid)
- options.video.set('url', videoData.url)
- options.video.set('category', videoData.category)
- options.video.set('licence', videoData.licence)
- options.video.set('language', videoData.language)
- options.video.set('description', videoData.description)
- options.video.set('support', videoData.support)
- options.video.set('nsfw', videoData.nsfw)
- options.video.set('commentsEnabled', videoData.commentsEnabled)
- options.video.set('waitTranscoding', videoData.waitTranscoding)
- options.video.set('state', videoData.state)
- options.video.set('duration', videoData.duration)
- options.video.set('createdAt', videoData.createdAt)
- options.video.set('publishedAt', videoData.publishedAt)
- options.video.set('privacy', videoData.privacy)
- options.video.set('channelId', videoData.channelId)
-
- if (options.updateViews === true) options.video.set('views', videoData.views)
- await options.video.save(sequelizeOptions)
-
- // Don't block on request
- generateThumbnailFromUrl(options.video, options.videoObject.icon)
- .catch(err => logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err }))
-
- // Remove old video files
- const videoFileDestroyTasks: Bluebird<void>[] = []
- for (const videoFile of options.video.VideoFiles) {
- videoFileDestroyTasks.push(videoFile.destroy(sequelizeOptions))
+ 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
+
+ await video.save(sequelizeOptions)
+
+ if (thumbnailModel) await video.addAndSaveThumbnail(thumbnailModel, t)
+
+ // FIXME: use icon URL instead
+ const previewUrl = buildRemoteBaseUrl(video, join(STATIC_PATHS.PREVIEWS, video.getPreview().filename))
+ const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE)
+ await video.addAndSaveThumbnail(previewModel, t)
+
+ {
+ const videoFileAttributes = videoFileActivityUrlToDBAttributes(video, videoObject)
+ const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a))
+
+ // Remove video files that do not exist anymore
+ const destroyTasks = video.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)
+ })
+
+ video.VideoFiles = await Promise.all(upsertTasks)