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 ++++++++++++++++++++++++++--- server/lib/job-queue/job-queue.ts | 4 +++- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'server/lib/job-queue') 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 } diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 0333464bd..69335acf0 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts @@ -7,7 +7,7 @@ import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' import { EmailPayload, processEmail } from './handlers/email' -import { processVideoFile, VideoFilePayload } from './handlers/video-file' +import { processVideoFile, processVideoImport, VideoFilePayload, VideoImportPayload } from './handlers/video-file' import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' type CreateJobArgument = @@ -15,6 +15,7 @@ type CreateJobArgument = { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } | { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } | { type: 'activitypub-follow', payload: ActivitypubFollowPayload } | + { type: 'video-file-import', payload: VideoImportPayload } | { type: 'video-file', payload: VideoFilePayload } | { type: 'email', payload: EmailPayload } @@ -23,6 +24,7 @@ const handlers: { [ id in JobType ]: (job: kue.Job) => Promise} = { 'activitypub-http-unicast': processActivityPubHttpUnicast, 'activitypub-http-fetcher': processActivityPubHttpFetcher, 'activitypub-follow': processActivityPubFollow, + 'video-file-import': processVideoImport, 'video-file': processVideoFile, 'email': processEmail } -- cgit v1.2.3