diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-16 16:25:53 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-18 13:38:09 +0100 |
commit | 90a8bd305de4153ec21137a73ff482dcc2e3e19b (patch) | |
tree | 2e35b5504ec11bc51579c92a70c77ed3d5ace816 /server/lib/job-queue | |
parent | 684cdacbbd775b5f404dd7b373e02dd21baf5ff0 (diff) | |
download | PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.tar.gz PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.tar.zst PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.zip |
Dissociate video file names and video uuid
Diffstat (limited to 'server/lib/job-queue')
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' | |||
2 | import { copy, stat } from 'fs-extra' | 2 | import { copy, stat } from 'fs-extra' |
3 | import { extname } from 'path' | 3 | import { extname } from 'path' |
4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | 4 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
5 | import { 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, MVideoWithFile } from '@server/types/models' | 7 | import { MVideoFile, 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' |
@@ -50,14 +50,16 @@ export { | |||
50 | 50 | ||
51 | // --------------------------------------------------------------------------- | 51 | // --------------------------------------------------------------------------- |
52 | 52 | ||
53 | async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) { | 53 | async 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' | |||
6 | import { Hooks } from '@server/lib/plugins/hooks' | 6 | import { Hooks } from '@server/lib/plugins/hooks' |
7 | import { isAbleToUploadVideo } from '@server/lib/user' | 7 | import { isAbleToUploadVideo } from '@server/lib/user' |
8 | import { addOptimizeOrMergeAudioJob } from '@server/lib/video' | 8 | import { addOptimizeOrMergeAudioJob } from '@server/lib/video' |
9 | import { getVideoFilePath } from '@server/lib/video-paths' | 9 | import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' |
10 | import { ThumbnailModel } from '@server/models/video/thumbnail' | 10 | import { ThumbnailModel } from '@server/models/video/thumbnail' |
11 | import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/types/models/video/video-import' | 11 | import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/types/models/video/video-import' |
12 | import { | 12 | import { |
@@ -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 | ||