]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-file.ts
Add user notification base code
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-file.ts
index ddbf6d1c23c9890ef6f4cdee635b989dbc8f1fcb..959cc04fa0b3b69849027ba4b425dc37f0f04fb5 100644 (file)
@@ -9,6 +9,7 @@ import { sequelizeTypescript } from '../../../initializers'
 import * as Bluebird from 'bluebird'
 import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
 import { importVideoFile, transcodeOriginalVideofile, optimizeVideofile } from '../../video-transcoding'
+import { Notifier } from '../../notifier'
 
 export type VideoFilePayload = {
   videoUUID: string
@@ -86,20 +87,21 @@ async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) {
 
     // If the video was not published, we consider it is a new one for other instances
     await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
+    if (isNewVideo) Notifier.Instance.notifyOnNewVideo(video)
 
     return undefined
   })
 }
 
-async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boolean) {
-  if (video === undefined) return undefined
+async function onVideoFileOptimizerSuccess (videoArg: VideoModel, isNewVideo: boolean) {
+  if (videoArg === undefined) return undefined
 
   // Outside the transaction (IO on disk)
-  const { videoFileResolution } = await video.getOriginalFileResolution()
+  const { videoFileResolution } = await videoArg.getOriginalFileResolution()
 
   return sequelizeTypescript.transaction(async t => {
     // Maybe the video changed in database, refresh it
-    const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
+    let videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t)
     // Video does not exist anymore
     if (!videoDatabase) return undefined
 
@@ -128,13 +130,14 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole
       logger.info('Transcoding jobs created for uuid %s.', videoDatabase.uuid, { resolutionsEnabled })
     } else {
       // No transcoding to do, it's now published
-      video.state = VideoState.PUBLISHED
-      video = await video.save({ transaction: t })
+      videoDatabase.state = VideoState.PUBLISHED
+      videoDatabase = await videoDatabase.save({ transaction: t })
 
-      logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid)
+      logger.info('No transcoding jobs created for video %s (no resolutions).', videoDatabase.uuid, { privacy: videoDatabase.privacy })
     }
 
-    return federateVideoIfNeeded(video, isNewVideo, t)
+    await federateVideoIfNeeded(videoDatabase, isNewVideo, t)
+    if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase)
   })
 }