]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/runners/job-files.ts
Prefer video studio instead of video edition
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / runners / job-files.ts
CommitLineData
0c9668f7 1import express from 'express'
5e47f6ab
C
2import { param } from 'express-validator'
3import { basename } from 'path'
4import { isSafeFilename } from '@server/helpers/custom-validators/misc'
ab14f0e0 5import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobStudioTranscodingPayload } from '@shared/models'
0c9668f7
C
6import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
7
8const tags = [ 'runner' ]
9
10export 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]
5e47f6ab
C
31
32export 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
ab14f0e0 40 const payload = res.locals.runnerJob.payload as RunnerJobStudioTranscodingPayload
5e47f6ab
C
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]