mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add ability to force transcoding
This commit is contained in:
@@ -3,6 +3,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
||||
import { Hooks } from '@server/lib/plugins/hooks'
|
||||
import { createTranscodingJobs } from '@server/lib/transcoding/create-transcoding-job'
|
||||
import { computeResolutionsToTranscode } from '@server/lib/transcoding/transcoding-resolutions'
|
||||
import { VideoJobInfoModel } from '@server/models/video/video-job-info'
|
||||
import { HttpStatusCode, UserRight, VideoState, VideoTranscodingCreate } from '@shared/models'
|
||||
import { asyncMiddleware, authenticate, createTranscodingValidator, ensureUserHasRight } from '../../../middlewares'
|
||||
|
||||
@@ -30,6 +31,8 @@ async function createTranscoding (req: express.Request, res: express.Response) {
|
||||
|
||||
const body: VideoTranscodingCreate = req.body
|
||||
|
||||
await VideoJobInfoModel.abortAllTasks(video.uuid, 'pendingTranscode')
|
||||
|
||||
const { resolution: maxResolution, hasAudio } = await video.probeMaxQualityFile()
|
||||
|
||||
const resolutions = await Hooks.wrapObject(
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import express from 'express'
|
||||
import { body } from 'express-validator'
|
||||
import { isBooleanValid, toBooleanOrNull } from '@server/helpers/custom-validators/misc'
|
||||
import { isValidCreateTranscodingType } from '@server/helpers/custom-validators/video-transcoding'
|
||||
import { CONFIG } from '@server/initializers/config'
|
||||
import { VideoJobInfoModel } from '@server/models/video/video-job-info'
|
||||
import { HttpStatusCode } from '@shared/models'
|
||||
import { HttpStatusCode, ServerErrorCode, VideoTranscodingCreate } from '@shared/models'
|
||||
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
|
||||
|
||||
const createTranscodingValidator = [
|
||||
@@ -12,6 +13,11 @@ const createTranscodingValidator = [
|
||||
body('transcodingType')
|
||||
.custom(isValidCreateTranscodingType),
|
||||
|
||||
body('forceTranscoding')
|
||||
.optional()
|
||||
.customSanitizer(toBooleanOrNull)
|
||||
.custom(isBooleanValid),
|
||||
|
||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
if (areValidationErrors(req, res)) return
|
||||
if (!await doesVideoExist(req.params.videoId, res, 'all')) return
|
||||
@@ -32,11 +38,14 @@ const createTranscodingValidator = [
|
||||
})
|
||||
}
|
||||
|
||||
// Prefer using job info table instead of video state because before 4.0 failed transcoded video were stuck in "TO_TRANSCODE" state
|
||||
const body = req.body as VideoTranscodingCreate
|
||||
if (body.forceTranscoding === true) return next()
|
||||
|
||||
const info = await VideoJobInfoModel.load(video.id)
|
||||
if (info && info.pendingTranscode > 0) {
|
||||
return res.fail({
|
||||
status: HttpStatusCode.CONFLICT_409,
|
||||
type: ServerErrorCode.VIDEO_ALREADY_BEING_TRANSCODED,
|
||||
message: 'This video is already being transcoded'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,15 +93,17 @@ describe('Test transcoding API validators', function () {
|
||||
await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'hls' })
|
||||
await waitJobs(servers)
|
||||
|
||||
await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video' })
|
||||
await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', forceTranscoding: true })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not run transcoding on a video that is already being transcoded', async function () {
|
||||
it('Should not run transcoding on a video that is already being transcoded if forceTranscoding is not set', async function () {
|
||||
await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video' })
|
||||
|
||||
const expectedStatus = HttpStatusCode.CONFLICT_409
|
||||
await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', expectedStatus })
|
||||
|
||||
await servers[0].videos.runTranscoding({ videoId: validId, transcodingType: 'web-video', forceTranscoding: true })
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
|
||||
Reference in New Issue
Block a user