aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/video-file-import.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/video-file-import.ts')
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts
index cd95aa075..86c9b5c29 100644
--- a/server/lib/job-queue/handlers/video-file-import.ts
+++ b/server/lib/job-queue/handlers/video-file-import.ts
@@ -2,9 +2,9 @@ import * as Bull from 'bull'
2import { copy, stat } from 'fs-extra' 2import { copy, stat } from 'fs-extra'
3import { extname } from 'path' 3import { extname } from 'path'
4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 4import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
5import { getVideoFilePath } from '@server/lib/video-paths' 5import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
6import { UserModel } from '@server/models/account/user' 6import { UserModel } from '@server/models/account/user'
7import { MVideoFile, MVideoWithFile } from '@server/types/models' 7import { MVideoFile, MVideoFullLight } from '@server/types/models'
8import { VideoFileImportPayload } from '@shared/models' 8import { VideoFileImportPayload } from '@shared/models'
9import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' 9import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils'
10import { logger } from '../../../helpers/logger' 10import { logger } from '../../../helpers/logger'
@@ -50,14 +50,16 @@ export {
50 50
51// --------------------------------------------------------------------------- 51// ---------------------------------------------------------------------------
52 52
53async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) { 53async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) {
54 const { videoFileResolution } = await getVideoFileResolution(inputFilePath) 54 const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
55 const { size } = await stat(inputFilePath) 55 const { size } = await stat(inputFilePath)
56 const fps = await getVideoFileFPS(inputFilePath) 56 const fps = await getVideoFileFPS(inputFilePath)
57 57
58 const fileExt = extname(inputFilePath)
58 let updatedVideoFile = new VideoFileModel({ 59 let updatedVideoFile = new VideoFileModel({
59 resolution: videoFileResolution, 60 resolution: videoFileResolution,
60 extname: extname(inputFilePath), 61 extname: fileExt,
62 filename: generateVideoFilename(video, false, videoFileResolution, fileExt),
61 size, 63 size,
62 fps, 64 fps,
63 videoId: video.id 65 videoId: video.id
@@ -68,7 +70,7 @@ async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) {
68 if (currentVideoFile) { 70 if (currentVideoFile) {
69 // Remove old file and old torrent 71 // Remove old file and old torrent
70 await video.removeFile(currentVideoFile) 72 await video.removeFile(currentVideoFile)
71 await video.removeTorrent(currentVideoFile) 73 await currentVideoFile.removeTorrent()
72 // Remove the old video file from the array 74 // Remove the old video file from the array
73 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) 75 video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
74 76
@@ -83,7 +85,7 @@ async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) {
83 const outputPath = getVideoFilePath(video, updatedVideoFile) 85 const outputPath = getVideoFilePath(video, updatedVideoFile)
84 await copy(inputFilePath, outputPath) 86 await copy(inputFilePath, outputPath)
85 87
86 await createTorrentAndSetInfoHash(video, updatedVideoFile) 88 await createTorrentAndSetInfoHash(video, video, updatedVideoFile)
87 89
88 await updatedVideoFile.save() 90 await updatedVideoFile.save()
89 91