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/middlewares/validators/config.ts | 12 +-- server/middlewares/validators/videos/index.ts | 2 +- .../middlewares/validators/videos/video-editor.ts | 112 --------------------- .../middlewares/validators/videos/video-studio.ts | 112 +++++++++++++++++++++ 4 files changed, 119 insertions(+), 119 deletions(-) delete mode 100644 server/middlewares/validators/videos/video-editor.ts create mode 100644 server/middlewares/validators/videos/video-studio.ts (limited to 'server/middlewares/validators') diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index e87b2e39d..1e839d577 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -57,7 +57,7 @@ const customConfigUpdateValidator = [ body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'), body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'), - body('videoEditor.enabled').isBoolean().withMessage('Should have a valid video editor enabled boolean'), + body('videoStudio.enabled').isBoolean().withMessage('Should have a valid video studio enabled boolean'), body('import.videos.concurrency').isInt({ min: 0 }).withMessage('Should have a valid import concurrency number'), body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), @@ -106,7 +106,7 @@ const customConfigUpdateValidator = [ if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return if (!checkInvalidTranscodingConfig(req.body, res)) return if (!checkInvalidLiveConfig(req.body, res)) return - if (!checkInvalidVideoEditorConfig(req.body, res)) return + if (!checkInvalidVideoStudioConfig(req.body, res)) return return next() } @@ -163,11 +163,11 @@ function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Respon return true } -function checkInvalidVideoEditorConfig (customConfig: CustomConfig, res: express.Response) { - if (customConfig.videoEditor.enabled === false) return true +function checkInvalidVideoStudioConfig (customConfig: CustomConfig, res: express.Response) { + if (customConfig.videoStudio.enabled === false) return true - if (customConfig.videoEditor.enabled === true && customConfig.transcoding.enabled === false) { - res.fail({ message: 'You cannot enable video editor if transcoding is not enabled' }) + if (customConfig.videoStudio.enabled === true && customConfig.transcoding.enabled === false) { + res.fail({ message: 'You cannot enable video studio if transcoding is not enabled' }) return false } diff --git a/server/middlewares/validators/videos/index.ts b/server/middlewares/validators/videos/index.ts index faa082510..c7dea4b3d 100644 --- a/server/middlewares/validators/videos/index.ts +++ b/server/middlewares/validators/videos/index.ts @@ -2,7 +2,6 @@ export * from './video-blacklist' export * from './video-captions' export * from './video-channels' export * from './video-comments' -export * from './video-editor' export * from './video-files' export * from './video-imports' export * from './video-live' @@ -10,5 +9,6 @@ export * from './video-ownership-changes' export * from './video-watch' export * from './video-rates' export * from './video-shares' +export * from './video-studio' export * from './video-transcoding' export * from './videos' diff --git a/server/middlewares/validators/videos/video-editor.ts b/server/middlewares/validators/videos/video-editor.ts deleted file mode 100644 index 9be97be93..000000000 --- a/server/middlewares/validators/videos/video-editor.ts +++ /dev/null @@ -1,112 +0,0 @@ -import express from 'express' -import { body, param } from 'express-validator' -import { isIdOrUUIDValid } from '@server/helpers/custom-validators/misc' -import { - isEditorCutTaskValid, - isEditorTaskAddIntroOutroValid, - isEditorTaskAddWatermarkValid, - isValidEditorTasksArray -} from '@server/helpers/custom-validators/video-editor' -import { cleanUpReqFiles } from '@server/helpers/express-utils' -import { CONFIG } from '@server/initializers/config' -import { approximateIntroOutroAdditionalSize, getTaskFile } from '@server/lib/video-editor' -import { isAudioFile } from '@shared/extra-utils' -import { HttpStatusCode, UserRight, VideoEditorCreateEdition, VideoEditorTask, VideoState } from '@shared/models' -import { logger } from '../../../helpers/logger' -import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared' - -const videosEditorAddEditionValidator = [ - param('videoId').custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), - - body('tasks').custom(isValidEditorTasksArray).withMessage('Should have a valid array of tasks'), - - async (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking videosEditorAddEditionValidator parameters.', { parameters: req.params, body: req.body, files: req.files }) - - if (CONFIG.VIDEO_EDITOR.ENABLED !== true) { - res.fail({ - status: HttpStatusCode.BAD_REQUEST_400, - message: 'Video editor is disabled on this instance' - }) - - return cleanUpReqFiles(req) - } - - if (areValidationErrors(req, res)) return cleanUpReqFiles(req) - - const body: VideoEditorCreateEdition = req.body - const files = req.files as Express.Multer.File[] - - for (let i = 0; i < body.tasks.length; i++) { - const task = body.tasks[i] - - if (!checkTask(req, task, i)) { - res.fail({ - status: HttpStatusCode.BAD_REQUEST_400, - message: `Task ${task.name} is invalid` - }) - - return cleanUpReqFiles(req) - } - - if (task.name === 'add-intro' || task.name === 'add-outro') { - const filePath = getTaskFile(files, i).path - - // Our concat filter needs a video stream - if (await isAudioFile(filePath)) { - res.fail({ - status: HttpStatusCode.BAD_REQUEST_400, - message: `Task ${task.name} is invalid: file does not contain a video stream` - }) - - return cleanUpReqFiles(req) - } - } - } - - if (!await doesVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) - - const video = res.locals.videoAll - if (video.state === VideoState.TO_TRANSCODE || video.state === VideoState.TO_EDIT) { - res.fail({ - status: HttpStatusCode.CONFLICT_409, - message: 'Cannot edit video that is already waiting for transcoding/edition' - }) - - return cleanUpReqFiles(req) - } - - const user = res.locals.oauth.token.User - if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req) - - // Try to make an approximation of bytes added by the intro/outro - const additionalBytes = await approximateIntroOutroAdditionalSize(video, body.tasks, i => getTaskFile(files, i).path) - if (await checkUserQuota(user, additionalBytes, res) === false) return cleanUpReqFiles(req) - - return next() - } -] - -// --------------------------------------------------------------------------- - -export { - videosEditorAddEditionValidator -} - -// --------------------------------------------------------------------------- - -const taskCheckers: { - [id in VideoEditorTask['name']]: (task: VideoEditorTask, indice?: number, files?: Express.Multer.File[]) => boolean -} = { - 'cut': isEditorCutTaskValid, - 'add-intro': isEditorTaskAddIntroOutroValid, - 'add-outro': isEditorTaskAddIntroOutroValid, - 'add-watermark': isEditorTaskAddWatermarkValid -} - -function checkTask (req: express.Request, task: VideoEditorTask, indice?: number) { - const checker = taskCheckers[task.name] - if (!checker) return false - - return checker(task, indice, req.files as Express.Multer.File[]) -} diff --git a/server/middlewares/validators/videos/video-studio.ts b/server/middlewares/validators/videos/video-studio.ts new file mode 100644 index 000000000..af7fe2283 --- /dev/null +++ b/server/middlewares/validators/videos/video-studio.ts @@ -0,0 +1,112 @@ +import express from 'express' +import { body, param } from 'express-validator' +import { isIdOrUUIDValid } from '@server/helpers/custom-validators/misc' +import { + isStudioCutTaskValid, + isStudioTaskAddIntroOutroValid, + isStudioTaskAddWatermarkValid, + isValidStudioTasksArray +} from '@server/helpers/custom-validators/video-studio' +import { cleanUpReqFiles } from '@server/helpers/express-utils' +import { CONFIG } from '@server/initializers/config' +import { approximateIntroOutroAdditionalSize, getTaskFile } from '@server/lib/video-studio' +import { isAudioFile } from '@shared/extra-utils' +import { HttpStatusCode, UserRight, VideoState, VideoStudioCreateEdition, VideoStudioTask } from '@shared/models' +import { logger } from '../../../helpers/logger' +import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared' + +const videoStudioAddEditionValidator = [ + param('videoId').custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), + + body('tasks').custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking videoStudioAddEditionValidator parameters.', { parameters: req.params, body: req.body, files: req.files }) + + if (CONFIG.VIDEO_STUDIO.ENABLED !== true) { + res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: 'Video studio is disabled on this instance' + }) + + return cleanUpReqFiles(req) + } + + if (areValidationErrors(req, res)) return cleanUpReqFiles(req) + + const body: VideoStudioCreateEdition = req.body + const files = req.files as Express.Multer.File[] + + for (let i = 0; i < body.tasks.length; i++) { + const task = body.tasks[i] + + if (!checkTask(req, task, i)) { + res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: `Task ${task.name} is invalid` + }) + + return cleanUpReqFiles(req) + } + + if (task.name === 'add-intro' || task.name === 'add-outro') { + const filePath = getTaskFile(files, i).path + + // Our concat filter needs a video stream + if (await isAudioFile(filePath)) { + res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: `Task ${task.name} is invalid: file does not contain a video stream` + }) + + return cleanUpReqFiles(req) + } + } + } + + if (!await doesVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req) + + const video = res.locals.videoAll + if (video.state === VideoState.TO_TRANSCODE || video.state === VideoState.TO_EDIT) { + res.fail({ + status: HttpStatusCode.CONFLICT_409, + message: 'Cannot edit video that is already waiting for transcoding/edition' + }) + + return cleanUpReqFiles(req) + } + + const user = res.locals.oauth.token.User + if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req) + + // Try to make an approximation of bytes added by the intro/outro + const additionalBytes = await approximateIntroOutroAdditionalSize(video, body.tasks, i => getTaskFile(files, i).path) + if (await checkUserQuota(user, additionalBytes, res) === false) return cleanUpReqFiles(req) + + return next() + } +] + +// --------------------------------------------------------------------------- + +export { + videoStudioAddEditionValidator +} + +// --------------------------------------------------------------------------- + +const taskCheckers: { + [id in VideoStudioTask['name']]: (task: VideoStudioTask, indice?: number, files?: Express.Multer.File[]) => boolean +} = { + 'cut': isStudioCutTaskValid, + 'add-intro': isStudioTaskAddIntroOutroValid, + 'add-outro': isStudioTaskAddIntroOutroValid, + 'add-watermark': isStudioTaskAddWatermarkValid +} + +function checkTask (req: express.Request, task: VideoStudioTask, indice?: number) { + const checker = taskCheckers[task.name] + if (!checker) return false + + return checker(task, indice, req.files as Express.Multer.File[]) +} -- cgit v1.2.3