diff options
author | Florent Fayolle <florent.fayolle69@gmail.com> | 2018-06-02 21:39:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-07 08:57:48 +0200 |
commit | 0138af9237b77dd7d3a49260d164193b4048de84 (patch) | |
tree | 5a377c7577cd99d5b324967187e10cd9fcc81383 /server/lib/job-queue | |
parent | 157b62b1f4450c32bb7383ccacbea555ec607013 (diff) | |
download | PeerTube-0138af9237b77dd7d3a49260d164193b4048de84.tar.gz PeerTube-0138af9237b77dd7d3a49260d164193b4048de84.tar.zst PeerTube-0138af9237b77dd7d3a49260d164193b4048de84.zip |
Add create-import-video-file-job command
Diffstat (limited to 'server/lib/job-queue')
-rw-r--r-- | server/lib/job-queue/handlers/video-file.ts | 29 | ||||
-rw-r--r-- | server/lib/job-queue/job-queue.ts | 4 |
2 files changed, 29 insertions, 4 deletions
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 = { | |||
16 | isPortraitMode?: boolean | 16 | isPortraitMode?: boolean |
17 | } | 17 | } |
18 | 18 | ||
19 | export type VideoImportPayload = { | ||
20 | videoUUID: string, | ||
21 | filePath: string | ||
22 | } | ||
23 | |||
24 | async function processVideoImport (job: kue.Job) { | ||
25 | const payload = job.data as VideoImportPayload | ||
26 | logger.info('Processing video import in job %d.', job.id) | ||
27 | |||
28 | const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(payload.videoUUID) | ||
29 | // No video, maybe deleted? | ||
30 | if (!video) { | ||
31 | logger.info('Do not process job %d, video does not exist.', job.id, { videoUUID: video.uuid }) | ||
32 | return undefined | ||
33 | } | ||
34 | |||
35 | await video.importVideoFile(payload.filePath) | ||
36 | |||
37 | await onVideoFileTranscoderOrImportSuccess(video) | ||
38 | return video | ||
39 | } | ||
40 | |||
19 | async function processVideoFile (job: kue.Job) { | 41 | async function processVideoFile (job: kue.Job) { |
20 | const payload = job.data as VideoFilePayload | 42 | const payload = job.data as VideoFilePayload |
21 | logger.info('Processing video file in job %d.', job.id) | 43 | logger.info('Processing video file in job %d.', job.id) |
@@ -30,7 +52,7 @@ async function processVideoFile (job: kue.Job) { | |||
30 | // Transcoding in other resolution | 52 | // Transcoding in other resolution |
31 | if (payload.resolution) { | 53 | if (payload.resolution) { |
32 | await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode) | 54 | await video.transcodeOriginalVideofile(payload.resolution, payload.isPortraitMode) |
33 | await onVideoFileTranscoderSuccess(video) | 55 | await onVideoFileTranscoderOrImportSuccess(video) |
34 | } else { | 56 | } else { |
35 | await video.optimizeOriginalVideofile() | 57 | await video.optimizeOriginalVideofile() |
36 | await onVideoFileOptimizerSuccess(video, payload.isNewVideo) | 58 | await onVideoFileOptimizerSuccess(video, payload.isNewVideo) |
@@ -39,7 +61,7 @@ async function processVideoFile (job: kue.Job) { | |||
39 | return video | 61 | return video |
40 | } | 62 | } |
41 | 63 | ||
42 | async function onVideoFileTranscoderSuccess (video: VideoModel) { | 64 | async function onVideoFileTranscoderOrImportSuccess (video: VideoModel) { |
43 | if (video === undefined) return undefined | 65 | if (video === undefined) return undefined |
44 | 66 | ||
45 | // Maybe the video changed in database, refresh it | 67 | // Maybe the video changed in database, refresh it |
@@ -109,5 +131,6 @@ async function onVideoFileOptimizerSuccess (video: VideoModel, isNewVideo: boole | |||
109 | // --------------------------------------------------------------------------- | 131 | // --------------------------------------------------------------------------- |
110 | 132 | ||
111 | export { | 133 | export { |
112 | processVideoFile | 134 | processVideoFile, |
135 | processVideoImport | ||
113 | } | 136 | } |
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 | |||
7 | import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' | 7 | import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' |
8 | import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' | 8 | import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' |
9 | import { EmailPayload, processEmail } from './handlers/email' | 9 | import { EmailPayload, processEmail } from './handlers/email' |
10 | import { processVideoFile, VideoFilePayload } from './handlers/video-file' | 10 | import { processVideoFile, processVideoImport, VideoFilePayload, VideoImportPayload } from './handlers/video-file' |
11 | import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' | 11 | import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' |
12 | 12 | ||
13 | type CreateJobArgument = | 13 | type CreateJobArgument = |
@@ -15,6 +15,7 @@ type CreateJobArgument = | |||
15 | { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } | | 15 | { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } | |
16 | { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } | | 16 | { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } | |
17 | { type: 'activitypub-follow', payload: ActivitypubFollowPayload } | | 17 | { type: 'activitypub-follow', payload: ActivitypubFollowPayload } | |
18 | { type: 'video-file-import', payload: VideoImportPayload } | | ||
18 | { type: 'video-file', payload: VideoFilePayload } | | 19 | { type: 'video-file', payload: VideoFilePayload } | |
19 | { type: 'email', payload: EmailPayload } | 20 | { type: 'email', payload: EmailPayload } |
20 | 21 | ||
@@ -23,6 +24,7 @@ const handlers: { [ id in JobType ]: (job: kue.Job) => Promise<any>} = { | |||
23 | 'activitypub-http-unicast': processActivityPubHttpUnicast, | 24 | 'activitypub-http-unicast': processActivityPubHttpUnicast, |
24 | 'activitypub-http-fetcher': processActivityPubHttpFetcher, | 25 | 'activitypub-http-fetcher': processActivityPubHttpFetcher, |
25 | 'activitypub-follow': processActivityPubFollow, | 26 | 'activitypub-follow': processActivityPubFollow, |
27 | 'video-file-import': processVideoImport, | ||
26 | 'video-file': processVideoFile, | 28 | 'video-file': processVideoFile, |
27 | 'email': processEmail | 29 | 'email': processEmail |
28 | } | 30 | } |