X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-file-import.ts;h=18823ee9c512b94d91ce231b268302398ea5e34a;hb=d487a997c80fafe6067016c6cd8e8afd6141baa3;hp=8cacb0ef3ea3b902f788b2d4e0f92fb1540b8320;hpb=79ad1706f3cf009e04db9cd9e6a721801d93e64e;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 8cacb0ef3..18823ee9c 100644 --- a/server/lib/job-queue/handlers/video-file-import.ts +++ b/server/lib/job-queue/handlers/video-file-import.ts @@ -1,16 +1,15 @@ import * as Bull from 'bull' +import { copy, stat } from 'fs-extra' +import { extname } from 'path' +import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' +import { getVideoFilePath } from '@server/lib/video-paths' +import { MVideoFile, MVideoWithFile } from '@server/types/models' +import { VideoFileImportPayload } from '@shared/models' +import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' import { logger } from '../../../helpers/logger' import { VideoModel } from '../../../models/video/video' -import { publishNewResolutionIfNeeded } from './video-transcoding' -import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' -import { copy, stat } from 'fs-extra' import { VideoFileModel } from '../../../models/video/video-file' -import { extname } from 'path' - -export type VideoFileImportPayload = { - videoUUID: string, - filePath: string -} +import { publishNewResolutionIfNeeded } from './video-transcoding' async function processVideoFileImport (job: Bull.Job) { const payload = job.data as VideoFileImportPayload @@ -37,7 +36,7 @@ export { // --------------------------------------------------------------------------- -async function updateVideoFile (video: VideoModel, inputFilePath: string) { +async function updateVideoFile (video: MVideoWithFile, inputFilePath: string) { const { videoFileResolution } = await getVideoFileResolution(inputFilePath) const { size } = await stat(inputFilePath) const fps = await getVideoFileFPS(inputFilePath) @@ -48,7 +47,7 @@ async function updateVideoFile (video: VideoModel, inputFilePath: string) { size, fps, videoId: video.id - }) + }) as MVideoFile const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution) @@ -60,17 +59,17 @@ async function updateVideoFile (video: VideoModel, inputFilePath: string) { video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) // Update the database - currentVideoFile.set('extname', updatedVideoFile.extname) - currentVideoFile.set('size', updatedVideoFile.size) - currentVideoFile.set('fps', updatedVideoFile.fps) + currentVideoFile.extname = updatedVideoFile.extname + currentVideoFile.size = updatedVideoFile.size + currentVideoFile.fps = updatedVideoFile.fps updatedVideoFile = currentVideoFile } - const outputPath = video.getVideoFilePath(updatedVideoFile) + const outputPath = getVideoFilePath(video, updatedVideoFile) await copy(inputFilePath, outputPath) - await video.createTorrentAndSetInfoHash(updatedVideoFile) + await createTorrentAndSetInfoHash(video, updatedVideoFile) await updatedVideoFile.save()