X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-file-import.ts;h=0d9e80cb86420f299469cd092120c3f6b08aaeee;hb=06aad80165d09a8863ab8103149a8ff518b10641;hp=8297a15716819c5fba66efeb3ef7d2be5f0f8f17;hpb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;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 8297a1571..0d9e80cb8 100644 --- a/server/lib/job-queue/handlers/video-file-import.ts +++ b/server/lib/job-queue/handlers/video-file-import.ts @@ -1,18 +1,20 @@ -import * as Bull from 'bull' +import { Job } from 'bull' import { copy, stat } from 'fs-extra' -import { extname } from 'path' +import { getLowercaseExtension } from '@shared/core-utils' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' -import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' -import { UserModel } from '@server/models/user/user' +import { CONFIG } from '@server/initializers/config' +import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' +import { generateWebTorrentVideoFilename } from '@server/lib/paths' +import { addMoveToObjectStorageJob } from '@server/lib/video' +import { VideoPathManager } from '@server/lib/video-path-manager' import { MVideoFullLight } from '@server/types/models' -import { VideoFileImportPayload } from '@shared/models' +import { VideoFileImportPayload, VideoStorage } from '@shared/models' import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' import { logger } from '../../../helpers/logger' import { VideoModel } from '../../../models/video/video' import { VideoFileModel } from '../../../models/video/video-file' -import { onNewWebTorrentFileResolution } from './video-transcoding' -async function processVideoFileImport (job: Bull.Job) { +async function processVideoFileImport (job: Job) { const payload = job.data as VideoFileImportPayload logger.info('Processing video file import in job %d.', job.id) @@ -23,21 +25,13 @@ async function processVideoFileImport (job: Bull.Job) { return undefined } - const data = await getVideoFileResolution(payload.filePath) - await updateVideoFile(video, payload.filePath) - const user = await UserModel.loadByChannelActorId(video.VideoChannel.actorId) - - const newResolutionPayload = { - type: 'new-resolution-to-webtorrent' as 'new-resolution-to-webtorrent', - videoUUID: video.uuid, - resolution: data.videoFileResolution, - isPortraitMode: data.isPortraitMode, - copyCodecs: false, - isNewVideo: false + if (CONFIG.OBJECT_STORAGE.ENABLED) { + await addMoveToObjectStorageJob(video) + } else { + await federateVideoIfNeeded(video, false) } - await onNewWebTorrentFileResolution(video, user, newResolutionPayload) return video } @@ -51,18 +45,17 @@ export { // --------------------------------------------------------------------------- async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { - const { videoFileResolution } = await getVideoFileResolution(inputFilePath) + const { resolution } = await getVideoFileResolution(inputFilePath) const { size } = await stat(inputFilePath) const fps = await getVideoFileFPS(inputFilePath) - const fileExt = extname(inputFilePath) + const fileExt = getLowercaseExtension(inputFilePath) - const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === videoFileResolution) + const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === resolution) if (currentVideoFile) { // Remove old file and old torrent - await video.removeFile(currentVideoFile) - await currentVideoFile.removeTorrent() + await video.removeWebTorrentFileAndTorrent(currentVideoFile) // Remove the old video file from the array video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile) @@ -70,15 +63,16 @@ async function updateVideoFile (video: MVideoFullLight, inputFilePath: string) { } const newVideoFile = new VideoFileModel({ - resolution: videoFileResolution, + resolution, extname: fileExt, - filename: generateVideoFilename(video, false, videoFileResolution, fileExt), + filename: generateWebTorrentVideoFilename(resolution, fileExt), + storage: VideoStorage.FILE_SYSTEM, size, fps, videoId: video.id }) - const outputPath = getVideoFilePath(video, newVideoFile) + const outputPath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, newVideoFile) await copy(inputFilePath, outputPath) video.VideoFiles.push(newVideoFile)