- await db.sequelize.transaction(async t => {
- const sequelizeOptions = { transaction: t }
-
- const videoData = {
- name: videoInfo.name,
- remote: false,
- extname: extname(videoPhysicalFile.filename),
- category: videoInfo.category,
- licence: videoInfo.licence,
- language: videoInfo.language,
- nsfw: videoInfo.nsfw,
- description: videoInfo.description,
- privacy: videoInfo.privacy,
- duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
- channelId: res.locals.videoChannel.id
- }
- const video = db.Video.build(videoData)
- video.url = getActivityPubUrl('video', video.uuid)
+ // Prepare data so we don't block the transaction
+ const videoData = {
+ name: videoInfo.name,
+ remote: false,
+ category: videoInfo.category,
+ licence: videoInfo.licence,
+ language: videoInfo.language,
+ commentsEnabled: videoInfo.commentsEnabled || false,
+ waitTranscoding: videoInfo.waitTranscoding || false,
+ state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED,
+ nsfw: videoInfo.nsfw || false,
+ description: videoInfo.description,
+ support: videoInfo.support,
+ privacy: videoInfo.privacy,
+ duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
+ channelId: res.locals.videoChannel.id
+ }
+ const video = new VideoModel(videoData)
+ video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object
+
+ // Build the file object
+ const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
+ const fps = await getVideoFileFPS(videoPhysicalFile.path)
+
+ const videoFileData = {
+ extname: extname(videoPhysicalFile.filename),
+ resolution: videoFileResolution,
+ size: videoPhysicalFile.size,
+ fps
+ }
+ const videoFile = new VideoFileModel(videoFileData)
+
+ // Move physical file
+ const videoDir = CONFIG.STORAGE.VIDEOS_DIR
+ const destination = join(videoDir, video.getVideoFilename(videoFile))
+ await rename(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']
+ if (thumbnailField) {
+ const thumbnailPhysicalFile = thumbnailField[0]
+ await processImage(thumbnailPhysicalFile, join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()), THUMBNAILS_SIZE)
+ } else {
+ await video.createThumbnail(videoFile)
+ }