X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-file-import.ts;fp=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-file-import.ts;h=8399163069e2c7b5dd2ef678223793afacd83354;hb=2451916e45420fedf556913ce121f3964c4b57d6;hp=86c9b5c29758731eaa7ecd058cdfc6ac5f2982e6;hpb=90a8bd305de4153ec21137a73ff482dcc2e3e19b;p=github%2FChocobozzz%2FPeerTube.git 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' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import { UserModel } from '@server/models/account/user' -import { MVideoFile, MVideoFullLight } from '@server/types/models' +import { MVideoFullLight } from '@server/types/models' import { VideoFileImportPayload } from '@shared/models' import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' import { logger } from '../../../helpers/logger' @@ -56,16 +56,8 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { const fps = await getVideoFileFPS(inputFilePath) const fileExt = extname(inputFilePath) - let updatedVideoFile = new VideoFileModel({ - resolution: videoFileResolution, - extname: fileExt, - filename: generateVideoFilename(video, false, videoFileResolution, fileExt), - size, - fps, - videoId: video.id - }) as MVideoFile - const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution) + const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution) if (currentVideoFile) { // Remove old file and old torrent @@ -74,20 +66,23 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { // Remove the old video file from the array video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) - // Update the database - currentVideoFile.extname = updatedVideoFile.extname - currentVideoFile.size = updatedVideoFile.size - currentVideoFile.fps = updatedVideoFile.fps - - updatedVideoFile = currentVideoFile + await currentVideoFile.destroy() } - const outputPath = getVideoFilePath(video, updatedVideoFile) - await copy(inputFilePath, outputPath) + const newVideoFile = new VideoFileModel({ + resolution: videoFileResolution, + extname: fileExt, + filename: generateVideoFilename(video, false, videoFileResolution, fileExt), + size, + fps, + videoId: video.id + }) - await createTorrentAndSetInfoHash(video, video, updatedVideoFile) + const outputPath = getVideoFilePath(video, newVideoFile) + await copy(inputFilePath, outputPath) - await updatedVideoFile.save() + video.VideoFiles.push(newVideoFile) + await createTorrentAndSetInfoHash(video, video, newVideoFile) - video.VideoFiles.push(updatedVideoFile) + await newVideoFile.save() }