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'
8 const tags = [ 'runner' ]
10 export const runnerJobGetVideoTranscodingFileValidator = [
11 isValidVideoIdParam('videoId'),
13 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 if (areValidationErrors(req, res)) return
16 if (!await doesVideoExist(req.params.videoId, res, 'all')) return
18 const runnerJob = res.locals.runnerJob
20 if (runnerJob.privatePayload.videoUUID !== res.locals.videoAll.uuid) {
22 status: HttpStatusCode.FORBIDDEN_403,
23 message: 'Job is not associated to this video',
24 tags: [ ...tags, res.locals.videoAll.uuid ]
32 export const runnerJobGetVideoStudioTaskFileValidator = [
33 param('filename').custom(v => isSafeFilename(v)),
35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 if (areValidationErrors(req, res)) return
38 const filename = req.params.filename
40 const payload = res.locals.runnerJob.payload as RunnerJobStudioTranscodingPayload
42 const found = Array.isArray(payload?.tasks) && payload.tasks.some(t => {
43 if (hasVideoStudioTaskFile(t)) {
44 return basename(t.options.file) === filename
52 status: HttpStatusCode.BAD_REQUEST_400,
53 message: 'File is not associated to this edition task',
54 tags: [ ...tags, res.locals.videoAll.uuid ]