diff options
Diffstat (limited to 'server/lib/job-queue/handlers/video-import.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-import.ts | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts index f9dda79f8..ff8c93328 100644 --- a/server/lib/job-queue/handlers/video-import.ts +++ b/server/lib/job-queue/handlers/video-import.ts | |||
@@ -111,13 +111,11 @@ type ProcessFileOptions = { | |||
111 | generateThumbnail: boolean | 111 | generateThumbnail: boolean |
112 | generatePreview: boolean | 112 | generatePreview: boolean |
113 | } | 113 | } |
114 | async function processFile (downloader: () => Promise<string>, videoImportArg: MVideoImportDefault, options: ProcessFileOptions) { | 114 | async function processFile (downloader: () => Promise<string>, videoImport: MVideoImportDefault, options: ProcessFileOptions) { |
115 | let tempVideoPath: string | 115 | let tempVideoPath: string |
116 | let videoDestFile: string | 116 | let videoDestFile: string |
117 | let videoFile: VideoFileModel | 117 | let videoFile: VideoFileModel |
118 | 118 | ||
119 | const videoImport = videoImportArg as MVideoImportDefaultFiles | ||
120 | |||
121 | try { | 119 | try { |
122 | // Download video from youtubeDL | 120 | // Download video from youtubeDL |
123 | tempVideoPath = await downloader() | 121 | tempVideoPath = await downloader() |
@@ -142,35 +140,37 @@ async function processFile (downloader: () => Promise<string>, videoImportArg: M | |||
142 | videoId: videoImport.videoId | 140 | videoId: videoImport.videoId |
143 | } | 141 | } |
144 | videoFile = new VideoFileModel(videoFileData) | 142 | videoFile = new VideoFileModel(videoFileData) |
143 | |||
144 | const videoWithFiles = Object.assign(videoImport.Video, { VideoFiles: [ videoFile ] }) | ||
145 | // To clean files if the import fails | 145 | // To clean files if the import fails |
146 | videoImport.Video.VideoFiles = [ videoFile ] | 146 | const videoImportWithFiles: MVideoImportDefaultFiles = Object.assign(videoImport, { Video: videoWithFiles }) |
147 | 147 | ||
148 | // Move file | 148 | // Move file |
149 | videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile)) | 149 | videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImportWithFiles.Video.getVideoFilename(videoFile)) |
150 | await move(tempVideoPath, videoDestFile) | 150 | await move(tempVideoPath, videoDestFile) |
151 | tempVideoPath = null // This path is not used anymore | 151 | tempVideoPath = null // This path is not used anymore |
152 | 152 | ||
153 | // Process thumbnail | 153 | // Process thumbnail |
154 | let thumbnailModel: MThumbnail | 154 | let thumbnailModel: MThumbnail |
155 | if (options.downloadThumbnail && options.thumbnailUrl) { | 155 | if (options.downloadThumbnail && options.thumbnailUrl) { |
156 | thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.MINIATURE) | 156 | thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.MINIATURE) |
157 | } else if (options.generateThumbnail || options.downloadThumbnail) { | 157 | } else if (options.generateThumbnail || options.downloadThumbnail) { |
158 | thumbnailModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.MINIATURE) | 158 | thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE) |
159 | } | 159 | } |
160 | 160 | ||
161 | // Process preview | 161 | // Process preview |
162 | let previewModel: MThumbnail | 162 | let previewModel: MThumbnail |
163 | if (options.downloadPreview && options.thumbnailUrl) { | 163 | if (options.downloadPreview && options.thumbnailUrl) { |
164 | previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.PREVIEW) | 164 | previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.PREVIEW) |
165 | } else if (options.generatePreview || options.downloadPreview) { | 165 | } else if (options.generatePreview || options.downloadPreview) { |
166 | previewModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.PREVIEW) | 166 | previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW) |
167 | } | 167 | } |
168 | 168 | ||
169 | // Create torrent | 169 | // Create torrent |
170 | await videoImport.Video.createTorrentAndSetInfoHash(videoFile) | 170 | await videoImportWithFiles.Video.createTorrentAndSetInfoHash(videoFile) |
171 | 171 | ||
172 | const { videoImportUpdated, video } = await sequelizeTypescript.transaction(async t => { | 172 | const { videoImportUpdated, video } = await sequelizeTypescript.transaction(async t => { |
173 | const videoImportToUpdate = videoImport as MVideoImportVideo | 173 | const videoImportToUpdate = videoImportWithFiles as MVideoImportVideo |
174 | 174 | ||
175 | // Refresh video | 175 | // Refresh video |
176 | const video = await VideoModel.load(videoImportToUpdate.videoId, t) | 176 | const video = await VideoModel.load(videoImportToUpdate.videoId, t) |