diff options
Diffstat (limited to 'server/middlewares/validators/videos/video-transcoding.ts')
-rw-r--r-- | server/middlewares/validators/videos/video-transcoding.ts | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/server/middlewares/validators/videos/video-transcoding.ts b/server/middlewares/validators/videos/video-transcoding.ts deleted file mode 100644 index 2f99ff42c..000000000 --- a/server/middlewares/validators/videos/video-transcoding.ts +++ /dev/null | |||
@@ -1,61 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { body } from 'express-validator' | ||
3 | import { isBooleanValid, toBooleanOrNull } from '@server/helpers/custom-validators/misc' | ||
4 | import { isValidCreateTranscodingType } from '@server/helpers/custom-validators/video-transcoding' | ||
5 | import { CONFIG } from '@server/initializers/config' | ||
6 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' | ||
7 | import { HttpStatusCode, ServerErrorCode, VideoTranscodingCreate } from '@shared/models' | ||
8 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | ||
9 | |||
10 | const createTranscodingValidator = [ | ||
11 | isValidVideoIdParam('videoId'), | ||
12 | |||
13 | body('transcodingType') | ||
14 | .custom(isValidCreateTranscodingType), | ||
15 | |||
16 | body('forceTranscoding') | ||
17 | .optional() | ||
18 | .customSanitizer(toBooleanOrNull) | ||
19 | .custom(isBooleanValid), | ||
20 | |||
21 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
22 | if (areValidationErrors(req, res)) return | ||
23 | if (!await doesVideoExist(req.params.videoId, res, 'all')) return | ||
24 | |||
25 | const video = res.locals.videoAll | ||
26 | |||
27 | if (video.remote) { | ||
28 | return res.fail({ | ||
29 | status: HttpStatusCode.BAD_REQUEST_400, | ||
30 | message: 'Cannot run transcoding job on a remote video' | ||
31 | }) | ||
32 | } | ||
33 | |||
34 | if (CONFIG.TRANSCODING.ENABLED !== true) { | ||
35 | return res.fail({ | ||
36 | status: HttpStatusCode.BAD_REQUEST_400, | ||
37 | message: 'Cannot run transcoding job because transcoding is disabled on this instance' | ||
38 | }) | ||
39 | } | ||
40 | |||
41 | const body = req.body as VideoTranscodingCreate | ||
42 | if (body.forceTranscoding === true) return next() | ||
43 | |||
44 | const info = await VideoJobInfoModel.load(video.id) | ||
45 | if (info && info.pendingTranscode > 0) { | ||
46 | return res.fail({ | ||
47 | status: HttpStatusCode.CONFLICT_409, | ||
48 | type: ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCODED, | ||
49 | message: 'This video is already being transcoded' | ||
50 | }) | ||
51 | } | ||
52 | |||
53 | return next() | ||
54 | } | ||
55 | ] | ||
56 | |||
57 | // --------------------------------------------------------------------------- | ||
58 | |||
59 | export { | ||
60 | createTranscodingValidator | ||
61 | } | ||