diff options
Diffstat (limited to 'server/middlewares/validators/runners')
-rw-r--r-- | server/middlewares/validators/runners/job-files.ts | 35 | ||||
-rw-r--r-- | server/middlewares/validators/runners/jobs.ts | 22 |
2 files changed, 56 insertions, 1 deletions
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 | ||