diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos/studio.ts | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/server/controllers/api/videos/studio.ts b/server/controllers/api/videos/studio.ts index 6667532bf..2ccb2fb89 100644 --- a/server/controllers/api/videos/studio.ts +++ b/server/controllers/api/videos/studio.ts | |||
@@ -1,8 +1,12 @@ | |||
1 | import Bluebird from 'bluebird' | ||
1 | import express from 'express' | 2 | import express from 'express' |
3 | import { move } from 'fs-extra' | ||
4 | import { basename, join } from 'path' | ||
2 | import { createAnyReqFiles } from '@server/helpers/express-utils' | 5 | import { createAnyReqFiles } from '@server/helpers/express-utils' |
6 | import { CONFIG } from '@server/initializers/config' | ||
3 | import { MIMETYPES } from '@server/initializers/constants' | 7 | import { MIMETYPES } from '@server/initializers/constants' |
4 | import { JobQueue } from '@server/lib/job-queue' | 8 | import { JobQueue } from '@server/lib/job-queue' |
5 | import { buildTaskFileFieldname, getTaskFile } from '@server/lib/video-studio' | 9 | import { buildTaskFileFieldname, getTaskFileFromReq } from '@server/lib/video-studio' |
6 | import { | 10 | import { |
7 | HttpStatusCode, | 11 | HttpStatusCode, |
8 | VideoState, | 12 | VideoState, |
@@ -68,7 +72,7 @@ async function createEditionTasks (req: express.Request, res: express.Response) | |||
68 | 72 | ||
69 | const payload = { | 73 | const payload = { |
70 | videoUUID: video.uuid, | 74 | videoUUID: video.uuid, |
71 | tasks: body.tasks.map((t, i) => buildTaskPayload(t, i, files)) | 75 | tasks: await Bluebird.mapSeries(body.tasks, (t, i) => buildTaskPayload(t, i, files)) |
72 | } | 76 | } |
73 | 77 | ||
74 | JobQueue.Instance.createJobAsync({ type: 'video-studio-edition', payload }) | 78 | JobQueue.Instance.createJobAsync({ type: 'video-studio-edition', payload }) |
@@ -77,7 +81,11 @@ async function createEditionTasks (req: express.Request, res: express.Response) | |||
77 | } | 81 | } |
78 | 82 | ||
79 | const taskPayloadBuilders: { | 83 | const taskPayloadBuilders: { |
80 | [id in VideoStudioTask['name']]: (task: VideoStudioTask, indice?: number, files?: Express.Multer.File[]) => VideoStudioTaskPayload | 84 | [id in VideoStudioTask['name']]: ( |
85 | task: VideoStudioTask, | ||
86 | indice?: number, | ||
87 | files?: Express.Multer.File[] | ||
88 | ) => Promise<VideoStudioTaskPayload> | ||
81 | } = { | 89 | } = { |
82 | 'add-intro': buildIntroOutroTask, | 90 | 'add-intro': buildIntroOutroTask, |
83 | 'add-outro': buildIntroOutroTask, | 91 | 'add-outro': buildIntroOutroTask, |
@@ -85,34 +93,46 @@ const taskPayloadBuilders: { | |||
85 | 'add-watermark': buildWatermarkTask | 93 | 'add-watermark': buildWatermarkTask |
86 | } | 94 | } |
87 | 95 | ||
88 | function buildTaskPayload (task: VideoStudioTask, indice: number, files: Express.Multer.File[]): VideoStudioTaskPayload { | 96 | function buildTaskPayload (task: VideoStudioTask, indice: number, files: Express.Multer.File[]): Promise<VideoStudioTaskPayload> { |
89 | return taskPayloadBuilders[task.name](task, indice, files) | 97 | return taskPayloadBuilders[task.name](task, indice, files) |
90 | } | 98 | } |
91 | 99 | ||
92 | function buildIntroOutroTask (task: VideoStudioTaskIntro | VideoStudioTaskOutro, indice: number, files: Express.Multer.File[]) { | 100 | async function buildIntroOutroTask (task: VideoStudioTaskIntro | VideoStudioTaskOutro, indice: number, files: Express.Multer.File[]) { |
101 | const destination = await moveStudioFileToPersistentTMP(getTaskFileFromReq(files, indice).path) | ||
102 | |||
93 | return { | 103 | return { |
94 | name: task.name, | 104 | name: task.name, |
95 | options: { | 105 | options: { |
96 | file: getTaskFile(files, indice).path | 106 | file: destination |
97 | } | 107 | } |
98 | } | 108 | } |
99 | } | 109 | } |
100 | 110 | ||
101 | function buildCutTask (task: VideoStudioTaskCut) { | 111 | function buildCutTask (task: VideoStudioTaskCut) { |
102 | return { | 112 | return Promise.resolve({ |
103 | name: task.name, | 113 | name: task.name, |
104 | options: { | 114 | options: { |
105 | start: task.options.start, | 115 | start: task.options.start, |
106 | end: task.options.end | 116 | end: task.options.end |
107 | } | 117 | } |
108 | } | 118 | }) |
109 | } | 119 | } |
110 | 120 | ||
111 | function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: number, files: Express.Multer.File[]) { | 121 | async function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: number, files: Express.Multer.File[]) { |
122 | const destination = await moveStudioFileToPersistentTMP(getTaskFileFromReq(files, indice).path) | ||
123 | |||
112 | return { | 124 | return { |
113 | name: task.name, | 125 | name: task.name, |
114 | options: { | 126 | options: { |
115 | file: getTaskFile(files, indice).path | 127 | file: destination |
116 | } | 128 | } |
117 | } | 129 | } |
118 | } | 130 | } |
131 | |||
132 | async function moveStudioFileToPersistentTMP (file: string) { | ||
133 | const destination = join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, basename(file)) | ||
134 | |||
135 | await move(file, destination) | ||
136 | |||
137 | return destination | ||
138 | } | ||