diff options
Diffstat (limited to 'server/middlewares/validators/runners/job-files.ts')
-rw-r--r-- | server/middlewares/validators/runners/job-files.ts | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/server/middlewares/validators/runners/job-files.ts b/server/middlewares/validators/runners/job-files.ts deleted file mode 100644 index 57c27fcfe..000000000 --- a/server/middlewares/validators/runners/job-files.ts +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { param } from 'express-validator' | ||
3 | import { basename } from 'path' | ||
4 | import { isSafeFilename } from '@server/helpers/custom-validators/misc' | ||
5 | import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobStudioTranscodingPayload } from '@shared/models' | ||
6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | ||
7 | |||
8 | const tags = [ 'runner' ] | ||
9 | |||
10 | export const runnerJobGetVideoTranscodingFileValidator = [ | ||
11 | isValidVideoIdParam('videoId'), | ||
12 | |||
13 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
14 | if (areValidationErrors(req, res)) return | ||
15 | |||
16 | if (!await doesVideoExist(req.params.videoId, res, 'all')) return | ||
17 | |||
18 | const runnerJob = res.locals.runnerJob | ||
19 | |||
20 | if (runnerJob.privatePayload.videoUUID !== res.locals.videoAll.uuid) { | ||
21 | return res.fail({ | ||
22 | status: HttpStatusCode.FORBIDDEN_403, | ||
23 | message: 'Job is not associated to this video', | ||
24 | tags: [ ...tags, res.locals.videoAll.uuid ] | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | return next() | ||
29 | } | ||
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 RunnerJobStudioTranscodingPayload | ||
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 | ] | ||