]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-transcoding.ts
Fix video upload with a capitalized ext
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-transcoding.ts
index e248b645e4f736bcd6bc954d19faed4d209352da..8d659daa6f1ce60d754072564c6e2c3e506158d0 100644 (file)
@@ -1,8 +1,8 @@
 import * as Bull from 'bull'
 import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils'
-import { JOB_PRIORITY } from '@server/initializers/constants'
-import { getJobTranscodingPriorityMalus, publishAndFederateIfNeeded } from '@server/lib/video'
+import { getTranscodingJobPriority, publishAndFederateIfNeeded } from '@server/lib/video'
 import { getVideoFilePath } from '@server/lib/video-paths'
+import { UserModel } from '@server/models/user/user'
 import { MUser, MUserId, MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models'
 import {
   HLSTranscodingPayload,
@@ -24,9 +24,8 @@ import {
   mergeAudioVideofile,
   optimizeOriginalVideofile,
   transcodeNewWebTorrentResolution
-} from '../../video-transcoding'
+} from '../../transcoding/video-transcoding'
 import { JobQueue } from '../job-queue'
-import { UserModel } from '@server/models/account/user'
 
 type HandlerFunction = (job: Bull.Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<any>
 
@@ -128,7 +127,7 @@ async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, pay
     // Remove webtorrent files if not enabled
     for (const file of video.VideoFiles) {
       await video.removeFile(file)
-      await video.removeTorrent(file)
+      await file.removeTorrent()
       await file.destroy()
     }
 
@@ -168,11 +167,11 @@ async function onVideoFileOptimizer (
       copyCodecs: transcodeType !== 'quick-transcode',
       isMaxQuality: true
     })
-    await createHlsJobIfEnabled(user, originalFileHLSPayload)
+    const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload)
 
     const hasNewResolutions = await createLowerResolutionsJobs(videoDatabase, user, videoFileResolution, isPortraitMode, 'webtorrent')
 
-    if (!hasNewResolutions) {
+    if (!hasHls && !hasNewResolutions) {
       // No transcoding to do, it's now published
       videoPublished = await videoDatabase.publishIfNeededAndSave(t)
     }
@@ -212,10 +211,10 @@ async function createHlsJobIfEnabled (user: MUserId, payload: {
   copyCodecs: boolean
   isMaxQuality: boolean
 }) {
-  if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return
+  if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return false
 
   const jobOptions = {
-    priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user)
+    priority: await getTranscodingJobPriority(user)
   }
 
   const hlsTranscodingPayload: HLSTranscodingPayload = {
@@ -227,7 +226,9 @@ async function createHlsJobIfEnabled (user: MUserId, payload: {
     isMaxQuality: payload.isMaxQuality
   }
 
-  return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: hlsTranscodingPayload }, jobOptions)
+  JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload }, jobOptions)
+
+  return true
 }
 
 async function createLowerResolutionsJobs (
@@ -239,16 +240,7 @@ async function createLowerResolutionsJobs (
 ) {
   // Create transcoding jobs if there are enabled resolutions
   const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod')
-  logger.info(
-    'Resolutions computed for video %s and origin file resolution of %d.', video.uuid, videoFileResolution,
-    { resolutions: resolutionsEnabled }
-  )
-
-  if (resolutionsEnabled.length === 0) {
-    logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid)
-
-    return false
-  }
+  const resolutionCreated: number[] = []
 
   for (const resolution of resolutionsEnabled) {
     let dataInput: VideoTranscodingPayload
@@ -274,14 +266,27 @@ async function createLowerResolutionsJobs (
       }
     }
 
+    if (!dataInput) continue
+
+    resolutionCreated.push(resolution)
+
     const jobOptions = {
-      priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user)
+      priority: await getTranscodingJobPriority(user)
     }
 
     JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }, jobOptions)
   }
 
-  logger.info('Transcoding jobs created for uuid %s.', video.uuid, { resolutionsEnabled })
+  if (resolutionCreated.length === 0) {
+    logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid)
+
+    return false
+  }
+
+  logger.info(
+    'New resolutions %s transcoding jobs created for video %s and origin file resolution of %d.', type, video.uuid, videoFileResolution,
+    { resolutionCreated }
+  )
 
   return true
 }