]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-file.ts
Add dev doc about localization
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-file.ts
index bd9412290ac1c34582b8bafe1b1392541cdb4784..93f9e9fe7784260afd459d5d567cf0de74b928cb 100644 (file)
@@ -11,7 +11,8 @@ import { JobQueue } from '../job-queue'
 
 export type VideoFilePayload = {
   videoUUID: string
-  resolution?: VideoResolution,
+  isNewVideo: boolean
+  resolution?: VideoResolution
   isPortraitMode?: boolean
 }
 
@@ -32,7 +33,7 @@ async function processVideoFile (job: kue.Job) {
     await onVideoFileTranscoderSuccess(video)
   } else {
     await video.optimizeOriginalVideofile()
-    await onVideoFileOptimizerSuccess(video)
+    await onVideoFileOptimizerSuccess(video, payload.isNewVideo)
   }
 
   return video
@@ -53,7 +54,7 @@ async function onVideoFileTranscoderSuccess (video: VideoModel) {
   return undefined
 }
 
-async function onVideoFileOptimizerSuccess (video: VideoModel) {
+async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boolean) {
   if (video === undefined) return undefined
 
   // Maybe the video changed in database, refresh it
@@ -62,9 +63,15 @@ async function onVideoFileOptimizerSuccess (video: VideoModel) {
   if (!videoDatabase) return undefined
 
   if (video.privacy !== VideoPrivacy.PRIVATE) {
-    // Now we'll add the video's meta data to our followers
-    await sendCreateVideo(video, undefined)
-    await shareVideoByServerAndChannel(video, undefined)
+    if (isNewVideo === true) {
+      // Now we'll add the video's meta data to our followers
+      await sequelizeTypescript.transaction(async t => {
+        await sendCreateVideo(video, t)
+        await shareVideoByServerAndChannel(video, t)
+      })
+    } else {
+      await sendUpdateVideo(video, undefined)
+    }
   }
 
   const { videoFileResolution } = await videoDatabase.getOriginalFileResolution()
@@ -77,27 +84,22 @@ async function onVideoFileOptimizerSuccess (video: VideoModel) {
   )
 
   if (resolutionsEnabled.length !== 0) {
-    try {
-      await sequelizeTypescript.transaction(async t => {
-        const tasks: Promise<any>[] = []
+    const tasks: Promise<any>[] = []
 
-        for (const resolution of resolutionsEnabled) {
-          const dataInput = {
-            videoUUID: videoDatabase.uuid,
-            resolution
-          }
+    for (const resolution of resolutionsEnabled) {
+      const dataInput = {
+        videoUUID: videoDatabase.uuid,
+        resolution,
+        isNewVideo
+      }
 
-          const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
-          tasks.push(p)
-        }
+      const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
+      tasks.push(p)
+    }
 
-        await Promise.all(tasks)
-      })
+    await Promise.all(tasks)
 
-      logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
-    } catch (err) {
-      logger.warn('Cannot transcode the video.', err)
-    }
+    logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
   } else {
     logger.info('No transcoding jobs created for video %s (no resolutions enabled).')
     return undefined