aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/runners/job-files.ts
blob: 56afa39aa1980d82bf741b0d547f3d4e7734e597 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import express from 'express'
import { HttpStatusCode } from '@shared/models'
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()
  }
]