From 5e47f6ab984a7d00782e4c7030afffa1ba480add Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 May 2023 15:29:34 +0200 Subject: Support studio transcoding in peertube runner --- server/helpers/custom-validators/misc.ts | 8 ++++++-- server/helpers/custom-validators/runners/jobs.ts | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index fa0f469f6..2c4cd1b9f 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -15,8 +15,12 @@ function isSafePath (p: string) { }) } -function isSafeFilename (filename: string, extension: string) { - return typeof filename === 'string' && !!filename.match(new RegExp(`^[a-z0-9-]+\\.${extension}$`)) +function isSafeFilename (filename: string, extension?: string) { + const regex = extension + ? new RegExp(`^[a-z0-9-]+\\.${extension}$`) + : new RegExp(`^[a-z0-9-]+\\.[a-z0-9]{1,8}$`) + + return typeof filename === 'string' && !!filename.match(regex) } function isSafePeerTubeFilenameWithoutExtension (filename: string) { diff --git a/server/helpers/custom-validators/runners/jobs.ts b/server/helpers/custom-validators/runners/jobs.ts index 5f755d5bb..934bd37c9 100644 --- a/server/helpers/custom-validators/runners/jobs.ts +++ b/server/helpers/custom-validators/runners/jobs.ts @@ -6,6 +6,7 @@ import { RunnerJobSuccessPayload, RunnerJobType, RunnerJobUpdatePayload, + VideoEditionTranscodingSuccess, VODAudioMergeTranscodingSuccess, VODHLSTranscodingSuccess, VODWebVideoTranscodingSuccess @@ -23,7 +24,8 @@ function isRunnerJobSuccessPayloadValid (value: RunnerJobSuccessPayload, type: R return isRunnerJobVODWebVideoResultPayloadValid(value as VODWebVideoTranscodingSuccess, type, files) || isRunnerJobVODHLSResultPayloadValid(value as VODHLSTranscodingSuccess, type, files) || isRunnerJobVODAudioMergeResultPayloadValid(value as VODHLSTranscodingSuccess, type, files) || - isRunnerJobLiveRTMPHLSResultPayloadValid(value as LiveRTMPHLSTranscodingSuccess, type) + isRunnerJobLiveRTMPHLSResultPayloadValid(value as LiveRTMPHLSTranscodingSuccess, type) || + isRunnerJobVideoEditionResultPayloadValid(value as VideoEditionTranscodingSuccess, type, files) } // --------------------------------------------------------------------------- @@ -35,6 +37,7 @@ function isRunnerJobProgressValid (value: string) { function isRunnerJobUpdatePayloadValid (value: RunnerJobUpdatePayload, type: RunnerJobType, files: UploadFilesForCheck) { return isRunnerJobVODWebVideoUpdatePayloadValid(value, type, files) || isRunnerJobVODHLSUpdatePayloadValid(value, type, files) || + isRunnerJobVideoEditionUpdatePayloadValid(value, type, files) || isRunnerJobVODAudioMergeUpdatePayloadValid(value, type, files) || isRunnerJobLiveRTMPHLSUpdatePayloadValid(value, type, files) } @@ -102,6 +105,15 @@ function isRunnerJobLiveRTMPHLSResultPayloadValid ( return type === 'live-rtmp-hls-transcoding' && (!value || (typeof value === 'object' && Object.keys(value).length === 0)) } +function isRunnerJobVideoEditionResultPayloadValid ( + _value: VideoEditionTranscodingSuccess, + type: RunnerJobType, + files: UploadFilesForCheck +) { + return type === 'video-edition-transcoding' && + isFileValid({ files, field: 'payload[videoFile]', mimeTypeRegex: null, maxSize: null }) +} + // --------------------------------------------------------------------------- function isRunnerJobVODWebVideoUpdatePayloadValid ( @@ -164,3 +176,12 @@ function isRunnerJobLiveRTMPHLSUpdatePayloadValid ( ) ) } + +function isRunnerJobVideoEditionUpdatePayloadValid ( + value: RunnerJobUpdatePayload, + type: RunnerJobType, + _files: UploadFilesForCheck +) { + return type === 'video-edition-transcoding' && + (!value || (typeof value === 'object' && Object.keys(value).length === 0)) +} -- cgit v1.2.3