]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
Begin moving video channel to actor
[github/Chocobozzz/PeerTube.git] / server / lib / jobs / transcoding-job-scheduler / video-file-optimizer-handler.ts
index e65ab3ee1df995b00b063738a9b375414afaad8e..7df048006b2b93be22640e93d0082d97ca997322 100644 (file)
@@ -1,14 +1,14 @@
 import * as Bluebird from 'bluebird'
 import { computeResolutionsToTranscode, logger } from '../../../helpers'
-import { database as db } from '../../../initializers/database'
-import { VideoInstance } from '../../../models'
-import { sendAddVideo } from '../../activitypub/send/send-add'
+import { sequelizeTypescript } from '../../../initializers'
+import { VideoModel } from '../../../models/video/video'
+import { shareVideoByServer } from '../../activitypub'
+import { sendCreateVideo } from '../../activitypub/send'
 import { JobScheduler } from '../job-scheduler'
 import { TranscodingJobPayload } from './transcoding-job-scheduler'
-import { shareVideoByServer } from '../../activitypub/share'
 
 async function process (data: TranscodingJobPayload, jobId: number) {
-  const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
+  const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(data.videoUUID)
   // No video, maybe deleted?
   if (!video) {
     logger.info('Do not process job %d, video does not exist.', jobId, { videoUUID: video.uuid })
@@ -25,18 +25,19 @@ function onError (err: Error, jobId: number) {
   return Promise.resolve()
 }
 
-async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: JobScheduler<TranscodingJobPayload, VideoInstance>) {
+async function onSuccess (jobId: number, video: VideoModel, jobScheduler: JobScheduler<TranscodingJobPayload, VideoModel>) {
   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.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
+  const videoDatabase = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(video.uuid)
   // Video does not exist anymore
   if (!videoDatabase) return undefined
 
   // Now we'll add the video's meta data to our followers
-  await sendAddVideo(video, undefined)
+  await sendCreateVideo(video, undefined)
+  // TODO: share by channel
   await shareVideoByServer(video, undefined)
 
   const originalFileHeight = await videoDatabase.getOriginalFileHeight()
@@ -50,7 +51,7 @@ async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: Job
 
   if (resolutionsEnabled.length !== 0) {
     try {
-      await db.sequelize.transaction(async t => {
+      await sequelizeTypescript.transaction(async t => {
         const tasks: Bluebird<any>[] = []
 
         for (const resolution of resolutionsEnabled) {