syncParam,
refreshViews
}
- const p = retryTransactionWrapper(refreshVideoIfNeeded, refreshOptions)
+ const p = refreshVideoIfNeeded(refreshOptions)
if (syncParam.refreshVideo === true) videoFromDatabase = await p
return { video: videoFromDatabase }
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))
- }
- await Promise.all(videoFileDestroyTasks)
+ {
+ const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject)
+ const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a))
- const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject)
- const tasks = videoFileAttributes.map(f => VideoFileModel.create(f, sequelizeOptions))
- await Promise.all(tasks)
+ // Remove video files that do not exist anymore
+ const destroyTasks = options.video.VideoFiles
+ .filter(f => !newVideoFiles.find(newFile => newFile.hasSameUniqueKeysThan(f)))
+ .map(f => f.destroy(sequelizeOptions))
+ await Promise.all(destroyTasks)
- // Update Tags
- const tags = options.videoObject.tag.map(tag => tag.name)
- const tagInstances = await TagModel.findOrCreateTags(tags, t)
- await options.video.$set('Tags', tagInstances, sequelizeOptions)
+ // Update or add other one
+ const upsertTasks = videoFileAttributes.map(a => VideoFileModel.upsert(a, sequelizeOptions))
+ await Promise.all(upsertTasks)
+ }
- // Update captions
- await VideoCaptionModel.deleteAllCaptionsOfRemoteVideo(options.video.id, t)
+ {
+ // Update Tags
+ const tags = options.videoObject.tag.map(tag => tag.name)
+ const tagInstances = await TagModel.findOrCreateTags(tags, t)
+ await options.video.$set('Tags', tagInstances, sequelizeOptions)
+ }
- const videoCaptionsPromises = options.videoObject.subtitleLanguage.map(c => {
- return VideoCaptionModel.insertOrReplaceLanguage(options.video.id, c.identifier, t)
- })
- await Promise.all(videoCaptionsPromises)
+ {
+ // Update captions
+ await VideoCaptionModel.deleteAllCaptionsOfRemoteVideo(options.video.id, t)
+
+ const videoCaptionsPromises = options.videoObject.subtitleLanguage.map(c => {
+ return VideoCaptionModel.insertOrReplaceLanguage(options.video.id, c.identifier, t)
+ })
+ await Promise.all(videoCaptionsPromises)
+ }
})
logger.info('Remote video with uuid %s updated', options.videoObject.uuid)
channel: channelActor.VideoChannel,
updateViews: options.refreshViews
}
- await updateVideoFromAP(updateOptions)
+ await retryTransactionWrapper(updateVideoFromAP, updateOptions)
await syncVideoExternalAttributes(video, videoObject, options.syncParam)
} catch (err) {
logger.warn('Cannot refresh video.', { err })