diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/transcoding.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-transcoding.ts | 13 | ||||
-rw-r--r-- | server/tests/api/check-params/transcoding.ts | 6 |
3 files changed, 18 insertions, 4 deletions
diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts index 54f484b2b..c0b93742f 100644 --- a/server/controllers/api/videos/transcoding.ts +++ b/server/controllers/api/videos/transcoding.ts | |||
@@ -3,6 +3,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' | |||
3 | import { Hooks } from '@server/lib/plugins/hooks' | 3 | import { Hooks } from '@server/lib/plugins/hooks' |
4 | import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job' | 4 | import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job' |
5 | import { computeResolutionsToTranscode } from '@server/lib/transcoding/transcoding-resolutions' | 5 | import { computeResolutionsToTranscode } from '@server/lib/transcoding/transcoding-resolutions' |
6 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' | ||
6 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' | 7 | import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models' |
7 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' | 8 | import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares' |
8 | 9 | ||
@@ -30,6 +31,8 @@ async function createTranscoding (req: express.Request, res: express.Response) { | |||
30 | 31 | ||
31 | const body: VideoTranscodingCreate = req.body | 32 | const body: VideoTranscodingCreate = req.body |
32 | 33 | ||
34 | await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingTranscode') | ||
35 | |||
33 | const { resolution: maxResolution, hasAudio } = await video.probeMaxQualityFile() | 36 | const { resolution: maxResolution, hasAudio } = await video.probeMaxQualityFile() |
34 | 37 | ||
35 | const resolutions = await Hooks.wrapObject( | 38 | const resolutions = await Hooks.wrapObject( |
diff --git a/server/middlewares/validators/videos/video-transcoding.ts b/server/middlewares/validators/videos/video-transcoding.ts index 3eb2d3141..2f99ff42c 100644 --- a/server/middlewares/validators/videos/video-transcoding.ts +++ b/server/middlewares/validators/videos/video-transcoding.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body } from 'express-validator' | 2 | import { body } from 'express-validator' |
3 | import { isBooleanValid, toBooleanOrNull } from '@server/helpers/custom-validators/misc' | ||
3 | import { isValidCreateTranscodingType } from '@server/helpers/custom-validators/video-transcoding' | 4 | import { isValidCreateTranscodingType } from '@server/helpers/custom-validators/video-transcoding' |
4 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
5 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' | 6 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' |
6 | import { HttpStatusCode } from '@shared/models' | 7 | import { HttpStatusCode, ServerErrorCode, VideoTranscodingCreate } from '@shared/models' |
7 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | 8 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' |
8 | 9 | ||
9 | const createTranscodingValidator = [ | 10 | const createTranscodingValidator = [ |
@@ -12,6 +13,11 @@ const createTranscodingValidator = [ | |||
12 | body('transcodingType') | 13 | body('transcodingType') |
13 | .custom(isValidCreateTranscodingType), | 14 | .custom(isValidCreateTranscodingType), |
14 | 15 | ||
16 | body('forceTranscoding') | ||
17 | .optional() | ||
18 | .customSanitizer(toBooleanOrNull) | ||
19 | .custom(isBooleanValid), | ||
20 | |||
15 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 21 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
16 | if (areValidationErrors(req, res)) return | 22 | if (areValidationErrors(req, res)) return |
17 | if (!await doesVideoExist(req.params.videoId, res, 'all')) return | 23 | if (!await doesVideoExist(req.params.videoId, res, 'all')) return |
@@ -32,11 +38,14 @@ const createTranscodingValidator = [ | |||
32 | }) | 38 | }) |
33 | } | 39 | } |
34 | 40 | ||
35 | // Prefer using job info table instead of video state because before 4.0 failed transcoded video were stuck in "TO_TRANSCODE" state | 41 | const body = req.body as VideoTranscodingCreate |
42 | if (body.forceTranscoding === true) return next() | ||
43 | |||
36 | const info = await VideoJobInfoModel.load(video.id) | 44 | const info = await VideoJobInfoModel.load(video.id) |
37 | if (info && info.pendingTranscode > 0) { | 45 | if (info && info.pendingTranscode > 0) { |
38 | return res.fail({ | 46 | return res.fail({ |
39 | status: HttpStatusCode.CONFLICT_409, | 47 | status: HttpStatusCode.CONFLICT_409, |
48 | type: ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCODED, | ||
40 | message: 'This video is already being transcoded' | 49 | message: 'This video is already being transcoded' |
41 | }) | 50 | }) |
42 | } | 51 | } |
diff --git a/server/tests/api/check-params/transcoding.ts b/server/tests/api/check-params/transcoding.ts index 4bebcb528..d5899e11b 100644 --- a/server/tests/api/check-params/transcoding.ts +++ b/server/tests/api/check-params/transcoding.ts | |||
@@ -93,15 +93,17 @@ describe('Test transcoding API validators', function () { | |||
93 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' }) | 93 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' }) |
94 | await waitJobs(servers) | 94 | await waitJobs(servers) |
95 | 95 | ||
96 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video' }) | 96 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', forceTranscoding: true }) |
97 | await waitJobs(servers) | 97 | await waitJobs(servers) |
98 | }) | 98 | }) |
99 | 99 | ||
100 | it('Should not run transcoding on a video that is already being transcoded', async function () { | 100 | it('Should not run transcoding on a video that is already being transcoded if forceTranscoding is not set', async function () { |
101 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video' }) | 101 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video' }) |
102 | 102 | ||
103 | const expectedStatus = HttpStatusCode.CONFLICT_409 | 103 | const expectedStatus = HttpStatusCode.CONFLICT_409 |
104 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', expectedStatus }) | 104 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', expectedStatus }) |
105 | |||
106 | await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', forceTranscoding: true }) | ||
105 | }) | 107 | }) |
106 | 108 | ||
107 | after(async function () { | 109 | after(async function () { |