From 92e66e04f7f51d37b465cff442ce47f6d6d7cadd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 22 Mar 2022 16:58:49 +0100 Subject: Rename studio to editor --- server/controllers/api/videos/editor.ts | 118 -------------------------------- server/controllers/api/videos/index.ts | 4 +- server/controllers/api/videos/studio.ts | 118 ++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 120 deletions(-) delete mode 100644 server/controllers/api/videos/editor.ts create mode 100644 server/controllers/api/videos/studio.ts (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/editor.ts b/server/controllers/api/videos/editor.ts deleted file mode 100644 index 588cc1a8c..000000000 --- a/server/controllers/api/videos/editor.ts +++ /dev/null @@ -1,118 +0,0 @@ -import express from 'express' -import { createAnyReqFiles } from '@server/helpers/express-utils' -import { MIMETYPES } from '@server/initializers/constants' -import { JobQueue } from '@server/lib/job-queue' -import { buildTaskFileFieldname, getTaskFile } from '@server/lib/video-editor' -import { - HttpStatusCode, - VideoEditionTaskPayload, - VideoEditorCreateEdition, - VideoEditorTask, - VideoEditorTaskCut, - VideoEditorTaskIntro, - VideoEditorTaskOutro, - VideoEditorTaskWatermark, - VideoState -} from '@shared/models' -import { asyncMiddleware, authenticate, videosEditorAddEditionValidator } from '../../../middlewares' - -const editorRouter = express.Router() - -const tasksFiles = createAnyReqFiles( - MIMETYPES.VIDEO.MIMETYPE_EXT, - (req: express.Request, file: Express.Multer.File, cb: (err: Error, result?: boolean) => void) => { - const body = req.body as VideoEditorCreateEdition - - // Fetch array element - const matches = file.fieldname.match(/tasks\[(\d+)\]/) - if (!matches) return cb(new Error('Cannot find array element indice for ' + file.fieldname)) - - const indice = parseInt(matches[1]) - const task = body.tasks[indice] - - if (!task) return cb(new Error('Cannot find array element of indice ' + indice + ' for ' + file.fieldname)) - - if ( - [ 'add-intro', 'add-outro', 'add-watermark' ].includes(task.name) && - file.fieldname === buildTaskFileFieldname(indice) - ) { - return cb(null, true) - } - - return cb(null, false) - } -) - -editorRouter.post('/:videoId/editor/edit', - authenticate, - tasksFiles, - asyncMiddleware(videosEditorAddEditionValidator), - asyncMiddleware(createEditionTasks) -) - -// --------------------------------------------------------------------------- - -export { - editorRouter -} - -// --------------------------------------------------------------------------- - -async function createEditionTasks (req: express.Request, res: express.Response) { - const files = req.files as Express.Multer.File[] - const body = req.body as VideoEditorCreateEdition - const video = res.locals.videoAll - - video.state = VideoState.TO_EDIT - await video.save() - - const payload = { - videoUUID: video.uuid, - tasks: body.tasks.map((t, i) => buildTaskPayload(t, i, files)) - } - - JobQueue.Instance.createJob({ type: 'video-edition', payload }) - - return res.sendStatus(HttpStatusCode.NO_CONTENT_204) -} - -const taskPayloadBuilders: { - [id in VideoEditorTask['name']]: (task: VideoEditorTask, indice?: number, files?: Express.Multer.File[]) => VideoEditionTaskPayload -} = { - 'add-intro': buildIntroOutroTask, - 'add-outro': buildIntroOutroTask, - 'cut': buildCutTask, - 'add-watermark': buildWatermarkTask -} - -function buildTaskPayload (task: VideoEditorTask, indice: number, files: Express.Multer.File[]): VideoEditionTaskPayload { - return taskPayloadBuilders[task.name](task, indice, files) -} - -function buildIntroOutroTask (task: VideoEditorTaskIntro | VideoEditorTaskOutro, indice: number, files: Express.Multer.File[]) { - return { - name: task.name, - options: { - file: getTaskFile(files, indice).path - } - } -} - -function buildCutTask (task: VideoEditorTaskCut) { - return { - name: task.name, - options: { - start: task.options.start, - end: task.options.end - } - } -} - -function buildWatermarkTask (task: VideoEditorTaskWatermark, indice: number, files: Express.Multer.File[]) { - return { - name: task.name, - options: { - file: getTaskFile(files, indice).path - } - } -} diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index a5ae07d95..c7617093c 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -35,7 +35,7 @@ import { VideoModel } from '../../../models/video/video' import { blacklistRouter } from './blacklist' import { videoCaptionsRouter } from './captions' import { videoCommentRouter } from './comment' -import { editorRouter } from './editor' +import { studioRouter } from './studio' import { filesRouter } from './files' import { videoImportsRouter } from './import' import { liveRouter } from './live' @@ -52,7 +52,7 @@ const videosRouter = express.Router() videosRouter.use('/', blacklistRouter) videosRouter.use('/', rateVideoRouter) videosRouter.use('/', videoCommentRouter) -videosRouter.use('/', editorRouter) +videosRouter.use('/', studioRouter) videosRouter.use('/', videoCaptionsRouter) videosRouter.use('/', videoImportsRouter) videosRouter.use('/', ownershipVideoRouter) diff --git a/server/controllers/api/videos/studio.ts b/server/controllers/api/videos/studio.ts new file mode 100644 index 000000000..bff344f3f --- /dev/null +++ b/server/controllers/api/videos/studio.ts @@ -0,0 +1,118 @@ +import express from 'express' +import { createAnyReqFiles } from '@server/helpers/express-utils' +import { MIMETYPES } from '@server/initializers/constants' +import { JobQueue } from '@server/lib/job-queue' +import { buildTaskFileFieldname, getTaskFile } from '@server/lib/video-studio' +import { + HttpStatusCode, + VideoState, + VideoStudioCreateEdition, + VideoStudioTask, + VideoStudioTaskCut, + VideoStudioTaskIntro, + VideoStudioTaskOutro, + VideoStudioTaskPayload, + VideoStudioTaskWatermark +} from '@shared/models' +import { asyncMiddleware, authenticate, videoStudioAddEditionValidator } from '../../../middlewares' + +const studioRouter = express.Router() + +const tasksFiles = createAnyReqFiles( + MIMETYPES.VIDEO.MIMETYPE_EXT, + (req: express.Request, file: Express.Multer.File, cb: (err: Error, result?: boolean) => void) => { + const body = req.body as VideoStudioCreateEdition + + // Fetch array element + const matches = file.fieldname.match(/tasks\[(\d+)\]/) + if (!matches) return cb(new Error('Cannot find array element indice for ' + file.fieldname)) + + const indice = parseInt(matches[1]) + const task = body.tasks[indice] + + if (!task) return cb(new Error('Cannot find array element of indice ' + indice + ' for ' + file.fieldname)) + + if ( + [ 'add-intro', 'add-outro', 'add-watermark' ].includes(task.name) && + file.fieldname === buildTaskFileFieldname(indice) + ) { + return cb(null, true) + } + + return cb(null, false) + } +) + +studioRouter.post('/:videoId/studio/edit', + authenticate, + tasksFiles, + asyncMiddleware(videoStudioAddEditionValidator), + asyncMiddleware(createEditionTasks) +) + +// --------------------------------------------------------------------------- + +export { + studioRouter +} + +// --------------------------------------------------------------------------- + +async function createEditionTasks (req: express.Request, res: express.Response) { + const files = req.files as Express.Multer.File[] + const body = req.body as VideoStudioCreateEdition + const video = res.locals.videoAll + + video.state = VideoState.TO_EDIT + await video.save() + + const payload = { + videoUUID: video.uuid, + tasks: body.tasks.map((t, i) => buildTaskPayload(t, i, files)) + } + + JobQueue.Instance.createJob({ type: 'video-studio-edition', payload }) + + return res.sendStatus(HttpStatusCode.NO_CONTENT_204) +} + +const taskPayloadBuilders: { + [id in VideoStudioTask['name']]: (task: VideoStudioTask, indice?: number, files?: Express.Multer.File[]) => VideoStudioTaskPayload +} = { + 'add-intro': buildIntroOutroTask, + 'add-outro': buildIntroOutroTask, + 'cut': buildCutTask, + 'add-watermark': buildWatermarkTask +} + +function buildTaskPayload (task: VideoStudioTask, indice: number, files: Express.Multer.File[]): VideoStudioTaskPayload { + return taskPayloadBuilders[task.name](task, indice, files) +} + +function buildIntroOutroTask (task: VideoStudioTaskIntro | VideoStudioTaskOutro, indice: number, files: Express.Multer.File[]) { + return { + name: task.name, + options: { + file: getTaskFile(files, indice).path + } + } +} + +function buildCutTask (task: VideoStudioTaskCut) { + return { + name: task.name, + options: { + start: task.options.start, + end: task.options.end + } + } +} + +function buildWatermarkTask (task: VideoStudioTaskWatermark, indice: number, files: Express.Multer.File[]) { + return { + name: task.name, + options: { + file: getTaskFile(files, indice).path + } + } +} -- cgit v1.2.3