diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-04 15:29:34 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 5e47f6ab984a7d00782e4c7030afffa1ba480add (patch) | |
tree | 1ce586b591a8d71acbc301eba29b9a5e6490439e /server/middlewares | |
parent | 6a4905602636afd6650c9e6f4d0fcc2105d91100 (diff) | |
download | PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.gz PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.tar.zst PeerTube-5e47f6ab984a7d00782e4c7030afffa1ba480add.zip |
Support studio transcoding in peertube runner
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/config.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/runners/job-files.ts | 35 | ||||
-rw-r--r-- | server/middlewares/validators/runners/jobs.ts | 22 |
3 files changed, 57 insertions, 1 deletions
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 = [ | |||
62 | body('transcoding.hls.enabled').isBoolean(), | 62 | body('transcoding.hls.enabled').isBoolean(), |
63 | 63 | ||
64 | body('videoStudio.enabled').isBoolean(), | 64 | body('videoStudio.enabled').isBoolean(), |
65 | body('videoStudio.remoteRunners.enabled').isBoolean(), | ||
65 | 66 | ||
66 | body('import.videos.concurrency').isInt({ min: 0 }), | 67 | body('import.videos.concurrency').isInt({ min: 0 }), |
67 | body('import.videos.http.enabled').isBoolean(), | 68 | 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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { HttpStatusCode } from '@shared/models' | 2 | import { param } from 'express-validator' |
3 | import { basename } from 'path' | ||
4 | import { isSafeFilename } from '@server/helpers/custom-validators/misc' | ||
5 | import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobVideoEditionTranscodingPayload } from '@shared/models' | ||
3 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | 6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' |
4 | 7 | ||
5 | const tags = [ 'runner' ] | 8 | const tags = [ 'runner' ] |
@@ -25,3 +28,33 @@ export const runnerJobGetVideoTranscodingFileValidator = [ | |||
25 | return next() | 28 | return next() |
26 | } | 29 | } |
27 | ] | 30 | ] |
31 | |||
32 | export const runnerJobGetVideoStudioTaskFileValidator = [ | ||
33 | param('filename').custom(v => isSafeFilename(v)), | ||
34 | |||
35 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
36 | if (areValidationErrors(req, res)) return | ||
37 | |||
38 | const filename = req.params.filename | ||
39 | |||
40 | const payload = res.locals.runnerJob.payload as RunnerJobVideoEditionTranscodingPayload | ||
41 | |||
42 | const found = Array.isArray(payload?.tasks) && payload.tasks.some(t => { | ||
43 | if (hasVideoStudioTaskFile(t)) { | ||
44 | return basename(t.options.file) === filename | ||
45 | } | ||
46 | |||
47 | return false | ||
48 | }) | ||
49 | |||
50 | if (!found) { | ||
51 | return res.fail({ | ||
52 | status: HttpStatusCode.BAD_REQUEST_400, | ||
53 | message: 'File is not associated to this edition task', | ||
54 | tags: [ ...tags, res.locals.videoAll.uuid ] | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | return next() | ||
59 | } | ||
60 | ] | ||
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 = [ | |||
91 | } | 91 | } |
92 | ] | 92 | ] |
93 | 93 | ||
94 | export const cancelRunnerJobValidator = [ | ||
95 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
96 | const runnerJob = res.locals.runnerJob | ||
97 | |||
98 | const allowedStates = new Set<RunnerJobState>([ | ||
99 | RunnerJobState.PENDING, | ||
100 | RunnerJobState.PROCESSING, | ||
101 | RunnerJobState.WAITING_FOR_PARENT_JOB | ||
102 | ]) | ||
103 | |||
104 | if (allowedStates.has(runnerJob.state) !== true) { | ||
105 | return res.fail({ | ||
106 | status: HttpStatusCode.BAD_REQUEST_400, | ||
107 | message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state', | ||
108 | tags | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | return next() | ||
113 | } | ||
114 | ] | ||
115 | |||
94 | export const runnerJobGetValidator = [ | 116 | export const runnerJobGetValidator = [ |
95 | param('jobUUID').custom(isUUIDValid), | 117 | param('jobUUID').custom(isUUIDValid), |
96 | 118 | ||