]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/job-queue/handlers/video-file-import.ts
Correctly remove torrents with HLS only
[github/Chocobozzz/PeerTube.git] / server / lib / job-queue / handlers / video-file-import.ts
index 5c5b7dccb77c5bac463080d492427d1b4ee5e2b3..582efea3a87df2a30fc9ac660c544d0227fbe022 100644 (file)
@@ -1,17 +1,16 @@
 import * as Bull from 'bull'
+import { copy, stat } from 'fs-extra'
+import { extname } from 'path'
+import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
+import { getVideoFilePath } from '@server/lib/video-paths'
+import { UserModel } from '@server/models/account/user'
+import { MVideoFile, MVideoWithFile } from '@server/types/models'
+import { VideoFileImportPayload } from '@shared/models'
+import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
 import { logger } from '../../../helpers/logger'
 import { VideoModel } from '../../../models/video/video'
-import { publishNewResolutionIfNeeded } from './video-transcoding'
-import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
-import { copy, stat } from 'fs-extra'
 import { VideoFileModel } from '../../../models/video/video-file'
-import { extname } from 'path'
-import { MVideoFile, MVideoWithFile } from '@server/typings/models'
-
-export type VideoFileImportPayload = {
-  videoUUID: string,
-  filePath: string
-}
+import { onNewWebTorrentFileResolution } from './video-transcoding'
 
 async function processVideoFileImport (job: Bull.Job) {
   const payload = job.data as VideoFileImportPayload
@@ -26,7 +25,9 @@ async function processVideoFileImport (job: Bull.Job) {
 
   await updateVideoFile(video, payload.filePath)
 
-  await publishNewResolutionIfNeeded(video)
+  const user = await UserModel.loadByChannelActorId(video.VideoChannel.actorId)
+  await onNewWebTorrentFileResolution(video, user)
+
   return video
 }
 
@@ -68,10 +69,10 @@ async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) {
     updatedVideoFile = currentVideoFile
   }
 
-  const outputPath = video.getVideoFilePath(updatedVideoFile)
+  const outputPath = getVideoFilePath(video, updatedVideoFile)
   await copy(inputFilePath, outputPath)
 
-  await video.createTorrentAndSetInfoHash(updatedVideoFile)
+  await createTorrentAndSetInfoHash(video, updatedVideoFile)
 
   await updatedVideoFile.save()