mirror of https://github.com/Chocobozzz/PeerTube
Don't transcribe/encode videos with invalid state
parent
2d26eff129
commit
f5104fb234
|
@ -273,12 +273,32 @@ export class Video implements VideoServerModel {
|
||||||
this.hasWebVideos()
|
this.hasWebVideos()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
canRunTranscoding (user: AuthUser) {
|
canRunTranscoding (user: AuthUser) {
|
||||||
return this.isLocal && !this.isLive && user?.hasRight(UserRight.RUN_VIDEO_TRANSCODING)
|
return this.isLocal &&
|
||||||
|
!this.isLive &&
|
||||||
|
user?.hasRight(UserRight.RUN_VIDEO_TRANSCODING) &&
|
||||||
|
this.state?.id &&
|
||||||
|
!this.transcodingAndTranscriptionIncompatibleStates().has(this.state.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
canGenerateTranscription (user: AuthUser, transcriptionEnabled: boolean) {
|
canGenerateTranscription (user: AuthUser, transcriptionEnabled: boolean) {
|
||||||
return transcriptionEnabled && this.isLocal && !this.isLive && user.hasRight(UserRight.UPDATE_ANY_VIDEO)
|
return transcriptionEnabled &&
|
||||||
|
this.isLocal &&
|
||||||
|
!this.isLive &&
|
||||||
|
user.hasRight(UserRight.UPDATE_ANY_VIDEO) &&
|
||||||
|
this.state?.id &&
|
||||||
|
!this.transcodingAndTranscriptionIncompatibleStates().has(this.state.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
private transcodingAndTranscriptionIncompatibleStates () {
|
||||||
|
return new Set<VideoStateType>([
|
||||||
|
VideoState.TO_IMPORT,
|
||||||
|
VideoState.TO_EDIT,
|
||||||
|
VideoState.TO_MOVE_TO_EXTERNAL_STORAGE,
|
||||||
|
VideoState.TO_MOVE_TO_FILE_SYSTEM
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import express from 'express'
|
|
||||||
import { HttpStatusCode, ServerErrorCode, ServerFilterHookName, VideoState, VideoStateType } from '@peertube/peertube-models'
|
import { HttpStatusCode, ServerErrorCode, ServerFilterHookName, VideoState, VideoStateType } from '@peertube/peertube-models'
|
||||||
import { isVideoFileMimeTypeValid, isVideoFileSizeValid } from '@server/helpers/custom-validators/videos.js'
|
import { isVideoFileMimeTypeValid, isVideoFileSizeValid } from '@server/helpers/custom-validators/videos.js'
|
||||||
import { logger } from '@server/helpers/logger.js'
|
import { logger } from '@server/helpers/logger.js'
|
||||||
import { CONSTRAINTS_FIELDS } from '@server/initializers/constants.js'
|
import { CONSTRAINTS_FIELDS, VIDEO_STATES } from '@server/initializers/constants.js'
|
||||||
import { isLocalVideoFileAccepted } from '@server/lib/moderation.js'
|
import { isLocalVideoFileAccepted } from '@server/lib/moderation.js'
|
||||||
import { Hooks } from '@server/lib/plugins/hooks.js'
|
import { Hooks } from '@server/lib/plugins/hooks.js'
|
||||||
import { MUserAccountId, MVideo } from '@server/types/models/index.js'
|
import { MUserAccountId, MVideo } from '@server/types/models/index.js'
|
||||||
|
import express from 'express'
|
||||||
import { checkUserQuota } from '../../shared/index.js'
|
import { checkUserQuota } from '../../shared/index.js'
|
||||||
|
|
||||||
export async function commonVideoFileChecks (options: {
|
export async function commonVideoFileChecks (options: {
|
||||||
|
@ -103,3 +103,37 @@ export function checkVideoFileCanBeEdited (video: MVideo, res: express.Response)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkVideoCanBeTranscribedOrTranscripted (video: MVideo, res: express.Response) {
|
||||||
|
if (video.remote) {
|
||||||
|
res.fail({
|
||||||
|
status: HttpStatusCode.BAD_REQUEST_400,
|
||||||
|
message: 'Cannot run this task on a remote video'
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (video.isLive) {
|
||||||
|
res.fail({
|
||||||
|
status: HttpStatusCode.BAD_REQUEST_400,
|
||||||
|
message: 'Cannot run this task on a live'
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const incompatibleStates = new Set<VideoStateType>([
|
||||||
|
VideoState.TO_IMPORT,
|
||||||
|
VideoState.TO_EDIT,
|
||||||
|
VideoState.TO_MOVE_TO_EXTERNAL_STORAGE,
|
||||||
|
VideoState.TO_MOVE_TO_FILE_SYSTEM
|
||||||
|
])
|
||||||
|
if (incompatibleStates.has(video.state)) {
|
||||||
|
res.fail({
|
||||||
|
status: HttpStatusCode.BAD_REQUEST_400,
|
||||||
|
message: `Cannot run this task on a video with "${VIDEO_STATES[video.state]}" state`
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
isValidVideoIdParam,
|
isValidVideoIdParam,
|
||||||
isValidVideoPasswordHeader
|
isValidVideoPasswordHeader
|
||||||
} from '../shared/index.js'
|
} from '../shared/index.js'
|
||||||
|
import { checkVideoCanBeTranscribedOrTranscripted } from './shared/video-validators.js'
|
||||||
|
|
||||||
export const addVideoCaptionValidator = [
|
export const addVideoCaptionValidator = [
|
||||||
isValidVideoIdParam('videoId'),
|
isValidVideoIdParam('videoId'),
|
||||||
|
@ -67,19 +68,7 @@ export const generateVideoCaptionValidator = [
|
||||||
|
|
||||||
const video = res.locals.videoAll
|
const video = res.locals.videoAll
|
||||||
|
|
||||||
if (video.remote) {
|
if (!checkVideoCanBeTranscribedOrTranscripted(video, res)) return
|
||||||
return res.fail({
|
|
||||||
status: HttpStatusCode.BAD_REQUEST_400,
|
|
||||||
message: 'Cannot run transcription job on a remote video'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (video.isLive) {
|
|
||||||
return res.fail({
|
|
||||||
status: HttpStatusCode.BAD_REQUEST_400,
|
|
||||||
message: 'Cannot run transcription job on a live'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the user who did the request is able to update the video
|
// Check if the user who did the request is able to update the video
|
||||||
const user = res.locals.oauth.token.User
|
const user = res.locals.oauth.token.User
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import express from 'express'
|
import { HttpStatusCode, ServerErrorCode, VideoTranscodingCreate } from '@peertube/peertube-models'
|
||||||
import { body } from 'express-validator'
|
|
||||||
import { isBooleanValid, toBooleanOrNull } from '@server/helpers/custom-validators/misc.js'
|
import { isBooleanValid, toBooleanOrNull } from '@server/helpers/custom-validators/misc.js'
|
||||||
import { isValidCreateTranscodingType } from '@server/helpers/custom-validators/video-transcoding.js'
|
import { isValidCreateTranscodingType } from '@server/helpers/custom-validators/video-transcoding.js'
|
||||||
import { CONFIG } from '@server/initializers/config.js'
|
import { CONFIG } from '@server/initializers/config.js'
|
||||||
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
|
import { VideoJobInfoModel } from '@server/models/video/video-job-info.js'
|
||||||
import { HttpStatusCode, ServerErrorCode, VideoTranscodingCreate } from '@peertube/peertube-models'
|
import express from 'express'
|
||||||
|
import { body } from 'express-validator'
|
||||||
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared/index.js'
|
import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared/index.js'
|
||||||
|
import { checkVideoCanBeTranscribedOrTranscripted } from './shared/video-validators.js'
|
||||||
|
|
||||||
const createTranscodingValidator = [
|
const createTranscodingValidator = [
|
||||||
isValidVideoIdParam('videoId'),
|
isValidVideoIdParam('videoId'),
|
||||||
|
@ -24,19 +25,7 @@ const createTranscodingValidator = [
|
||||||
|
|
||||||
const video = res.locals.videoAll
|
const video = res.locals.videoAll
|
||||||
|
|
||||||
if (video.remote) {
|
if (!checkVideoCanBeTranscribedOrTranscripted(video, res)) return
|
||||||
return res.fail({
|
|
||||||
status: HttpStatusCode.BAD_REQUEST_400,
|
|
||||||
message: 'Cannot run transcoding job on a remote video'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (video.isLive) {
|
|
||||||
return res.fail({
|
|
||||||
status: HttpStatusCode.BAD_REQUEST_400,
|
|
||||||
message: 'Cannot run transcoding job on a live'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CONFIG.TRANSCODING.ENABLED !== true) {
|
if (CONFIG.TRANSCODING.ENABLED !== true) {
|
||||||
return res.fail({
|
return res.fail({
|
||||||
|
|
Loading…
Reference in New Issue