diff options
Diffstat (limited to 'server/lib/job-queue/handlers/video-file-import.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-file-import.ts | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts index 86c9b5c29..839916306 100644 --- a/server/lib/job-queue/handlers/video-file-import.ts +++ b/server/lib/job-queue/handlers/video-file-import.ts | |||
@@ -4,7 +4,7 @@ import { extname } from 'path' | |||
4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | 4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
5 | import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' | 5 | import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' |
6 | import { UserModel } from '@server/models/account/user' | 6 | import { UserModel } from '@server/models/account/user' |
7 | import { MVideoFile, MVideoFullLight } from '@server/types/models' | 7 | import { MVideoFullLight } from '@server/types/models' |
8 | import { VideoFileImportPayload } from '@shared/models' | 8 | import { VideoFileImportPayload } from '@shared/models' |
9 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' | 9 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' |
10 | import { logger } from '../../../helpers/logger' | 10 | import { logger } from '../../../helpers/logger' |
@@ -56,16 +56,8 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { | |||
56 | const fps = await getVideoFileFPS(inputFilePath) | 56 | const fps = await getVideoFileFPS(inputFilePath) |
57 | 57 | ||
58 | const fileExt = extname(inputFilePath) | 58 | const fileExt = extname(inputFilePath) |
59 | let updatedVideoFile = new VideoFileModel({ | ||
60 | resolution: videoFileResolution, | ||
61 | extname: fileExt, | ||
62 | filename: generateVideoFilename(video, false, videoFileResolution, fileExt), | ||
63 | size, | ||
64 | fps, | ||
65 | videoId: video.id | ||
66 | }) as MVideoFile | ||
67 | 59 | ||
68 | const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution) | 60 | const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution) |
69 | 61 | ||
70 | if (currentVideoFile) { | 62 | if (currentVideoFile) { |
71 | // Remove old file and old torrent | 63 | // Remove old file and old torrent |
@@ -74,20 +66,23 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { | |||
74 | // Remove the old video file from the array | 66 | // Remove the old video file from the array |
75 | video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) | 67 | video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) |
76 | 68 | ||
77 | // Update the database | 69 | await currentVideoFile.destroy() |
78 | currentVideoFile.extname = updatedVideoFile.extname | ||
79 | currentVideoFile.size = updatedVideoFile.size | ||
80 | currentVideoFile.fps = updatedVideoFile.fps | ||
81 | |||
82 | updatedVideoFile = currentVideoFile | ||
83 | } | 70 | } |
84 | 71 | ||
85 | const outputPath = getVideoFilePath(video, updatedVideoFile) | 72 | const newVideoFile = new VideoFileModel({ |
86 | await copy(inputFilePath, outputPath) | 73 | resolution: videoFileResolution, |
74 | extname: fileExt, | ||
75 | filename: generateVideoFilename(video, false, videoFileResolution, fileExt), | ||
76 | size, | ||
77 | fps, | ||
78 | videoId: video.id | ||
79 | }) | ||
87 | 80 | ||
88 | await createTorrentAndSetInfoHash(video, video, updatedVideoFile) | 81 | const outputPath = getVideoFilePath(video, newVideoFile) |
82 | await copy(inputFilePath, outputPath) | ||
89 | 83 | ||
90 | await updatedVideoFile.save() | 84 | video.VideoFiles.push(newVideoFile) |
85 | await createTorrentAndSetInfoHash(video, video, newVideoFile) | ||
91 | 86 | ||
92 | video.VideoFiles.push(updatedVideoFile) | 87 | await newVideoFile.save() |
93 | } | 88 | } |