2023-04-21 07:55:10 -05:00
|
|
|
import express from 'express'
|
2023-05-04 08:29:34 -05:00
|
|
|
import { param } from 'express-validator'
|
|
|
|
import { basename } from 'path'
|
|
|
|
import { isSafeFilename } from '@server/helpers/custom-validators/misc'
|
2023-05-04 08:55:51 -05:00
|
|
|
import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobStudioTranscodingPayload } from '@shared/models'
|
2023-04-21 07:55:10 -05:00
|
|
|
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
|
|
|
|
|
|
|
|
const tags = [ 'runner' ]
|
|
|
|
|
|
|
|
export const runnerJobGetVideoTranscodingFileValidator = [
|
|
|
|
isValidVideoIdParam('videoId'),
|
|
|
|
|
|
|
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
if (!await doesVideoExist(req.params.videoId, res, 'all')) return
|
|
|
|
|
|
|
|
const runnerJob = res.locals.runnerJob
|
|
|
|
|
|
|
|
if (runnerJob.privatePayload.videoUUID !== res.locals.videoAll.uuid) {
|
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.FORBIDDEN_403,
|
|
|
|
message: 'Job is not associated to this video',
|
|
|
|
tags: [ ...tags, res.locals.videoAll.uuid ]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|
2023-05-04 08:29:34 -05:00
|
|
|
|
|
|
|
export const runnerJobGetVideoStudioTaskFileValidator = [
|
|
|
|
param('filename').custom(v => isSafeFilename(v)),
|
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
if (areValidationErrors(req, res)) return
|
|
|
|
|
|
|
|
const filename = req.params.filename
|
|
|
|
|
2023-05-04 08:55:51 -05:00
|
|
|
const payload = res.locals.runnerJob.payload as RunnerJobStudioTranscodingPayload
|
2023-05-04 08:29:34 -05:00
|
|
|
|
|
|
|
const found = Array.isArray(payload?.tasks) && payload.tasks.some(t => {
|
|
|
|
if (hasVideoStudioTaskFile(t)) {
|
|
|
|
return basename(t.options.file) === filename
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
return res.fail({
|
|
|
|
status: HttpStatusCode.BAD_REQUEST_400,
|
|
|
|
message: 'File is not associated to this edition task',
|
|
|
|
tags: [ ...tags, res.locals.videoAll.uuid ]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
]
|