X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-file-import.ts;h=be9e7d181b0e65aa91ab29176a0edc8c69302bba;hb=a3b7421abb4192e215aa280418b62e96958c5e42;hp=921d9a083081fc1ec76bd62612e49f73a43edaf9;hpb=97567dd81f508dd6295ac4d73d849aa2ce0a6549;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 921d9a083..be9e7d181 100644 --- a/server/lib/job-queue/handlers/video-file-import.ts +++ b/server/lib/job-queue/handlers/video-file-import.ts @@ -1,14 +1,17 @@ import * as Bull from 'bull' import { logger } from '../../../helpers/logger' import { VideoModel } from '../../../models/video/video' -import { publishVideoIfNeeded } from './video-transcoding' +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' +import { MVideoFile, MVideoWithFile } from '@server/typings/models' +import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' +import { getVideoFilePath } from '@server/lib/video-paths' export type VideoFileImportPayload = { - videoUUID: string, + videoUUID: string filePath: string } @@ -25,7 +28,7 @@ async function processVideoFileImport (job: Bull.Job) { await updateVideoFile(video, payload.filePath) - await publishVideoIfNeeded(video) + await publishNewResolutionIfNeeded(video) return video } @@ -37,7 +40,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 +51,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 +63,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()