aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts14
-rw-r--r--server/lib/job-queue/handlers/video-import.ts8
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts2
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts2
4 files changed, 15 insertions, 11 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
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 0d00c1b9d..8fa024105 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -6,7 +6,7 @@ import { isPostImportVideoAccepted } from '@server/lib/moderation'
6import { Hooks } from '@server/lib/plugins/hooks' 6import { Hooks } from '@server/lib/plugins/hooks'
7import { isAbleToUploadVideo } from '@server/lib/user' 7import { isAbleToUploadVideo } from '@server/lib/user'
8import { addOptimizeOrMergeAudioJob } from '@server/lib/video' 8import { addOptimizeOrMergeAudioJob } from '@server/lib/video'
9import { getVideoFilePath } from '@server/lib/video-paths' 9import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
10import { ThumbnailModel } from '@server/models/video/thumbnail' 10import { ThumbnailModel } from '@server/models/video/thumbnail'
11import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/types/models/video/video-import' 11import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/types/models/video/video-import'
12import { 12import {
@@ -116,10 +116,12 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
116 const duration = await getDurationFromVideoFile(tempVideoPath) 116 const duration = await getDurationFromVideoFile(tempVideoPath)
117 117
118 // Prepare video file object for creation in database 118 // Prepare video file object for creation in database
119 const fileExt = extname(tempVideoPath)
119 const videoFileData = { 120 const videoFileData = {
120 extname: extname(tempVideoPath), 121 extname: fileExt,
121 resolution: videoFileResolution, 122 resolution: videoFileResolution,
122 size: stats.size, 123 size: stats.size,
124 filename: generateVideoFilename(videoImport.Video, false, videoFileResolution, fileExt),
123 fps, 125 fps,
124 videoId: videoImport.videoId 126 videoId: videoImport.videoId
125 } 127 }
@@ -183,7 +185,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
183 } 185 }
184 186
185 // Create torrent 187 // Create torrent
186 await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoFile) 188 await createTorrentAndSetInfoHash(videoImportWithFiles.Video, videoImportWithFiles.Video, videoFile)
187 189
188 const videoFileSave = videoFile.toJSON() 190 const videoFileSave = videoFile.toJSON()
189 191
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index 6d50635bb..d57202ca5 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -85,7 +85,7 @@ async function saveLive (video: MVideo, live: MVideoLive) {
85 await video.save() 85 await video.save()
86 86
87 // Remove old HLS playlist video files 87 // Remove old HLS playlist video files
88 const videoWithFiles = await VideoModel.loadWithFiles(video.id) 88 const videoWithFiles = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.id)
89 89
90 const hlsPlaylist = videoWithFiles.getHLSPlaylist() 90 const hlsPlaylist = videoWithFiles.getHLSPlaylist()
91 await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id) 91 await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id)
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index e248b645e..8573d4d12 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -128,7 +128,7 @@ async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, pay
128 // Remove webtorrent files if not enabled 128 // Remove webtorrent files if not enabled
129 for (const file of video.VideoFiles) { 129 for (const file of video.VideoFiles) {
130 await video.removeFile(file) 130 await video.removeFile(file)
131 await video.removeTorrent(file) 131 await file.removeTorrent()
132 await file.destroy() 132 await file.destroy()
133 } 133 }
134 134