diff options
Diffstat (limited to 'server/middlewares/validators/runners')
-rw-r--r-- | server/middlewares/validators/runners/jobs.ts | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/server/middlewares/validators/runners/jobs.ts b/server/middlewares/validators/runners/jobs.ts index 384b209ba..62f9340a5 100644 --- a/server/middlewares/validators/runners/jobs.ts +++ b/server/middlewares/validators/runners/jobs.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isUUIDValid } from '@server/helpers/custom-validators/misc' | 3 | import { exists, isUUIDValid } from '@server/helpers/custom-validators/misc' |
4 | import { | 4 | import { |
5 | isRunnerJobAbortReasonValid, | 5 | isRunnerJobAbortReasonValid, |
6 | isRunnerJobArrayOfStateValid, | ||
6 | isRunnerJobErrorMessageValid, | 7 | isRunnerJobErrorMessageValid, |
7 | isRunnerJobProgressValid, | 8 | isRunnerJobProgressValid, |
8 | isRunnerJobSuccessPayloadValid, | 9 | isRunnerJobSuccessPayloadValid, |
@@ -12,7 +13,9 @@ import { | |||
12 | import { isRunnerTokenValid } from '@server/helpers/custom-validators/runners/runners' | 13 | import { isRunnerTokenValid } from '@server/helpers/custom-validators/runners/runners' |
13 | import { cleanUpReqFiles } from '@server/helpers/express-utils' | 14 | import { cleanUpReqFiles } from '@server/helpers/express-utils' |
14 | import { LiveManager } from '@server/lib/live' | 15 | import { LiveManager } from '@server/lib/live' |
16 | import { runnerJobCanBeCancelled } from '@server/lib/runners' | ||
15 | import { RunnerJobModel } from '@server/models/runner/runner-job' | 17 | import { RunnerJobModel } from '@server/models/runner/runner-job' |
18 | import { arrayify } from '@shared/core-utils' | ||
16 | import { | 19 | import { |
17 | HttpStatusCode, | 20 | HttpStatusCode, |
18 | RunnerJobLiveRTMPHLSTranscodingPrivatePayload, | 21 | RunnerJobLiveRTMPHLSTranscodingPrivatePayload, |
@@ -119,13 +122,7 @@ export const cancelRunnerJobValidator = [ | |||
119 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 122 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
120 | const runnerJob = res.locals.runnerJob | 123 | const runnerJob = res.locals.runnerJob |
121 | 124 | ||
122 | const allowedStates = new Set<RunnerJobState>([ | 125 | if (runnerJobCanBeCancelled(runnerJob) !== true) { |
123 | RunnerJobState.PENDING, | ||
124 | RunnerJobState.PROCESSING, | ||
125 | RunnerJobState.WAITING_FOR_PARENT_JOB | ||
126 | ]) | ||
127 | |||
128 | if (allowedStates.has(runnerJob.state) !== true) { | ||
129 | return res.fail({ | 126 | return res.fail({ |
130 | status: HttpStatusCode.BAD_REQUEST_400, | 127 | status: HttpStatusCode.BAD_REQUEST_400, |
131 | message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state', | 128 | message: 'Cannot cancel this job that is not in "pending", "processing" or "waiting for parent job" state', |
@@ -137,6 +134,21 @@ export const cancelRunnerJobValidator = [ | |||
137 | } | 134 | } |
138 | ] | 135 | ] |
139 | 136 | ||
137 | export const listRunnerJobsValidator = [ | ||
138 | query('search') | ||
139 | .optional() | ||
140 | .custom(exists), | ||
141 | |||
142 | query('stateOneOf') | ||
143 | .optional() | ||
144 | .customSanitizer(arrayify) | ||
145 | .custom(isRunnerJobArrayOfStateValid), | ||
146 | |||
147 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
148 | return next() | ||
149 | } | ||
150 | ] | ||
151 | |||
140 | export const runnerJobGetValidator = [ | 152 | export const runnerJobGetValidator = [ |
141 | param('jobUUID').custom(isUUIDValid), | 153 | param('jobUUID').custom(isUUIDValid), |
142 | 154 | ||