+
+ if (videoFile.isAudio()) {
+ videoFile.resolution = DEFAULT_AUDIO_RESOLUTION
+ } else {
+ videoFile.fps = await getVideoFileFPS(videoPhysicalFile.path)
+ videoFile.resolution = (await getVideoFileResolution(videoPhysicalFile.path)).videoFileResolution
+ }
+
+ // Move physical file
+ const videoDir = CONFIG.STORAGE.VIDEOS_DIR
+ const destination = join(videoDir, video.getVideoFilename(videoFile))
+ await move(videoPhysicalFile.path, destination)
+ // This is important in case if there is another attempt in the retry process
+ videoPhysicalFile.filename = video.getVideoFilename(videoFile)
+ videoPhysicalFile.path = destination
+
+ // Process thumbnail or create it from the video
+ const thumbnailField = req.files['thumbnailfile']
+ const thumbnailModel = thumbnailField
+ ? await createVideoMiniatureFromExisting(thumbnailField[0].path, video, ThumbnailType.MINIATURE)
+ : await generateVideoMiniature(video, videoFile, ThumbnailType.MINIATURE)
+
+ // Process preview or create it from the video
+ const previewField = req.files['previewfile']
+ const previewModel = previewField
+ ? await createVideoMiniatureFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW)
+ : await generateVideoMiniature(video, videoFile, ThumbnailType.PREVIEW)
+
+ // Create the torrent file
+ await video.createTorrentAndSetInfoHash(videoFile)
+
+ const { videoCreated, videoWasAutoBlacklisted } = await sequelizeTypescript.transaction(async t => {
+ const sequelizeOptions = { transaction: t }
+
+ const videoCreated = await video.save(sequelizeOptions)
+
+ await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
+ await videoCreated.addAndSaveThumbnail(previewModel, t)
+
+ // Do not forget to add video channel information to the created video
+ videoCreated.VideoChannel = res.locals.videoChannel
+
+ videoFile.videoId = video.id
+ await videoFile.save(sequelizeOptions)
+
+ video.VideoFiles = [ videoFile ]
+
+ // Create tags
+ if (videoInfo.tags !== undefined) {
+ const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t)
+
+ await video.$set('Tags', tagInstances, sequelizeOptions)
+ video.Tags = tagInstances
+ }
+
+ // Schedule an update in the future?
+ if (videoInfo.scheduleUpdate) {
+ await ScheduleVideoUpdateModel.create({
+ videoId: video.id,
+ updateAt: videoInfo.scheduleUpdate.updateAt,
+ privacy: videoInfo.scheduleUpdate.privacy || null
+ }, { transaction: t })
+ }
+
+ const videoWasAutoBlacklisted = await autoBlacklistVideoIfNeeded(video, res.locals.oauth.token.User, t)
+ if (!videoWasAutoBlacklisted) await federateVideoIfNeeded(video, true, t)
+
+ auditLogger.create(getAuditIdFromRes(res), new VideoAuditView(videoCreated.toFormattedDetailsJSON()))
+ logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)
+
+ return { videoCreated, videoWasAutoBlacklisted }