From 5e47f6ab984a7d00782e4c7030afffa1ba480add Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 May 2023 15:29:34 +0200 Subject: Support studio transcoding in peertube runner --- server/middlewares/validators/config.ts | 1 + server/middlewares/validators/runners/job-files.ts | 35 +++++++++++++++++++++- server/middlewares/validators/runners/jobs.ts | 22 ++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index b3e7e5011..a0074cb24 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -62,6 +62,7 @@ const customConfigUpdateValidator = [ body('transcoding.hls.enabled').isBoolean(), body('videoStudio.enabled').isBoolean(), + body('videoStudio.remoteRunners.enabled').isBoolean(), body('import.videos.concurrency').isInt({ min: 0 }), body('import.videos.http.enabled').isBoolean(), diff --git a/server/middlewares/validators/runners/job-files.ts b/server/middlewares/validators/runners/job-files.ts index 56afa39aa..e5afff0e5 100644 --- a/server/middlewares/validators/runners/job-files.ts +++ b/server/middlewares/validators/runners/job-files.ts @@ -1,5 +1,8 @@ import express from 'express' -import { HttpStatusCode } from '@shared/models' +import { param } from 'express-validator' +import { basename } from 'path' +import { isSafeFilename } from '@server/helpers/custom-validators/misc' +import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobVideoEditionTranscodingPayload } from '@shared/models' import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' const tags = [ 'runner' ] @@ -25,3 +28,33 @@ export const runnerJobGetVideoTranscodingFileValidator = [ return next() } ] + +export const runnerJobGetVideoStudioTaskFileValidator = [ + param('filename').custom(v => isSafeFilename(v)), + + (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (areValidationErrors(req, res)) return + + const filename = req.params.filename + + const payload = res.locals.runnerJob.payload as RunnerJobVideoEditionTranscodingPayload + + const found = Array.isArray(payload?.tasks) && payload.tasks.some(t => { + if (hasVideoStudioTaskFile(t)) { + return basename(t.options.file) === filename + } + + return false + }) + + if (!found) { + return res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: 'File is not associated to this edition task', + tags: [ ...tags, res.locals.videoAll.uuid ] + }) + } + + return next() + } +] diff --git a/server/middlewares/validators/runners/jobs.ts b/server/middlewares/validators/runners/jobs.ts index 8cb87e946..de956a1ca 100644 --- a/server/middlewares/validators/runners/jobs.ts +++ b/server/middlewares/validators/runners/jobs.ts @@ -91,6 +91,28 @@ export const successRunnerJobValidator = [ } ] +export const cancelRunnerJobValidator = [ + (req: express.Request, res: express.Response, next: express.NextFunction) => { + const runnerJob = res.locals.runnerJob + + const allowedStates = new Set([ + RunnerJobState.PENDING, + RunnerJobState.PROCESSING, + RunnerJobState.WAITING_FOR_PARENT_JOB + ]) + + if (allowedStates.has(runnerJob.state) !== true) { + return res.fail({ + status: HttpStatusCode.BAD_REQUEST_400, + message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state', + tags + }) + } + + return next() + } +] + export const runnerJobGetValidator = [ param('jobUUID').custom(isUUIDValid), -- cgit v1.2.3