]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
Rename Pod -> Server
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / transcoding-job-scheduler / video-file-optimizer-handler.ts
index f019c28bc8d168a0ee22f80dc58828bb73fab2d2..d3ee886e7f535e7d394aa1088fad0b6e9739675b 100644 (file)
@@ -1,13 +1,14 @@
 import * as Bluebird from 'bluebird'
+import { computeResolutionsToTranscode, logger } from '../../../helpers'
 
 import { database as db } from '../../../initializers/database'
-import { logger, computeResolutionsToTranscode } from '../../../helpers'
 import { VideoInstance } from '../../../models'
-import { addVideoToFriends } from '../../friends'
+import { sendAddVideo } from '../../activitypub/send-request'
 import { JobScheduler } from '../job-scheduler'
+import { TranscodingJobPayload } from './transcoding-job-scheduler'
 
-async function process (data: { videoUUID: string }, jobId: number) {
-  const video = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(data.videoUUID)
+async function process (data: TranscodingJobPayload, jobId: number) {
+  const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
   // No video, maybe deleted?
   if (!video) {
     logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
@@ -24,20 +25,18 @@ function onError (err: Error, jobId: number) {
   return Promise.resolve()
 }
 
-async function onSuccess (jobId: number, video: VideoInstance) {
+async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: JobScheduler<TranscodingJobPayload, VideoInstance>) {
   if (video === undefined) return undefined
 
   logger.info('Job %d is a success.', jobId)
 
   // Maybe the video changed in database, refresh it
-  const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndPodAndTags(video.uuid)
+  const videoDatabase = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
   // Video does not exist anymore
   if (!videoDatabase) return undefined
 
-  const remoteVideo = await videoDatabase.toAddRemoteJSON()
-
-  // Now we'll add the video's meta data to our friends
-  await addVideoToFriends(remoteVideo, null)
+  // Now we'll add the video's meta data to our followers
+  await sendAddVideo(video, undefined)
 
   const originalFileHeight = await videoDatabase.getOriginalFileHeight()
   // Create transcoding jobs if there are enabled resolutions
@@ -59,7 +58,7 @@ async function onSuccess (jobId: number, video: VideoInstance) {
             resolution
           }
 
-          const p = JobScheduler.Instance.createJob(t, 'videoFileTranscoder', dataInput)
+          const p = jobScheduler.createJob(t, 'videoFileTranscoder', dataInput)
           tasks.push(p)
         }