From 0138af9237b77dd7d3a49260d164193b4048de84 Mon Sep 17 00:00:00 2001 From: Florent Fayolle Date: Sat, 2 Jun 2018 21:39:41 +0200 Subject: Add create-import-video-file-job command --- server/lib/job-queue/handlers/video-file.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'server/lib/job-queue/handlers/video-file.ts') diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts index 93f9e9fe7..38eb3511c 100644 --- a/server/lib/job-queue/handlers/video-file.ts +++ b/server/lib/job-queue/handlers/video-file.ts @@ -16,6 +16,28 @@ export type VideoFilePayload = { isPortraitMode?: boolean } +export type VideoImportPayload = { + videoUUID: string, + filePath: string +} + +async function processVideoImport (job: kue.Job) { + const payload = job.data as VideoImportPayload + logger.info('Processing video import in job %d.', job.id) + + const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(payload.videoUUID) + // No video, maybe deleted? + if (!video) { + logger.info('Do not process job %d, video does not exist.', job.id, { videoUUID: video.uuid }) + return undefined + } + + await video.importVideoFile(payload.filePath) + + await onVideoFileTranscoderOrImportSuccess(video) + return video +} + async function processVideoFile (job: kue.Job) { const payload = job.data as VideoFilePayload logger.info('Processing video file in job %d.', job.id) @@ -30,7 +52,7 @@ async function processVideoFile (job: kue.Job) { // Transcoding in other resolution if (payload.resolution) { await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode) - await onVideoFileTranscoderSuccess(video) + await onVideoFileTranscoderOrImportSuccess(video) } else { await video.optimizeOriginalVideofile() await onVideoFileOptimizerSuccess(video, payload.isNewVideo) @@ -39,7 +61,7 @@ async function processVideoFile (job: kue.Job) { return video } -async function onVideoFileTranscoderSuccess (video: VideoModel) { +async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { if (video === undefined) return undefined // Maybe the video changed in database, refresh it @@ -109,5 +131,6 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole // --------------------------------------------------------------------------- export { - processVideoFile + processVideoFile, + processVideoImport } -- cgit v1.2.3