]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/runners/job-files.ts
Support studio transcoding in peertube runner
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / runners / job-files.ts
index 56afa39aa1980d82bf741b0d547f3d4e7734e597..e5afff0e5bd065f3506361303bf8da1230c8e3db 100644 (file)
@@ -1,5 +1,8 @@
 import express from 'express'
-import { HttpStatusCode } from '@shared/models'
+import { param } from 'express-validator'
+import { basename } from 'path'
+import { isSafeFilename } from '@server/helpers/custom-validators/misc'
+import { hasVideoStudioTaskFile, HttpStatusCode, RunnerJobVideoEditionTranscodingPayload } from '@shared/models'
 import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
 
 const tags = [ 'runner' ]
@@ -25,3 +28,33 @@ export const runnerJobGetVideoTranscodingFileValidator = [
     return next()
   }
 ]
+
+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
+
+    const payload = res.locals.runnerJob.payload as RunnerJobVideoEditionTranscodingPayload
+
+    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()
+  }
+]