ActivityPub-federated video streaming platform using P2P directly in your web browser
Check caption file content
Chocobozzzaf9381a4532f
diff --git a/server/core/controllers/api/videos/captions.ts b/server/core/controllers/api/videos/captions.tsindex bae110d44c..f381a79462 100644--- a/server/core/controllers/api/videos/captions.ts+++ b/server/core/controllers/api/videos/captions.ts@@ -1,4 +1,5 @@import { HttpStatusCode, VideoCaptionGenerate, VideoChannelActivityAction } from '@peertube/peertube-models'+import { isVTTFileValid } from '@server/helpers/custom-validators/video-captions.js'import { retryTransactionWrapper } from '@server/helpers/database-utils.js'import { Hooks } from '@server/lib/plugins/hooks.js'import { createLocalCaption, createTranscriptionTaskIfNeeded, updateHLSMasterOnCaptionChangeIfNeeded } from '@server/lib/video-captions.js'@@ -79,14 +80,19 @@ async function listVideoCaptions (req: express.Request, res: express.Response) {async function createVideoCaption (req: express.Request, res: express.Response) {const videoCaptionPhysicalFile: Express.Multer.File = req.files['captionfile'][0]+ const captionPath = videoCaptionPhysicalFile.pathconst video = res.locals.videoFull+ if (!await isVTTFileValid(captionPath)) {+ return res.fail({ status: HttpStatusCode.BAD_REQUEST_400, message: req.t('Invalid caption file') })+ }+const captionLanguage = req.params.captionLanguageconst videoCaption = await createLocalCaption({video,language: captionLanguage,- path: videoCaptionPhysicalFile.path,+ path: captionPath,automaticallyGenerated: false})diff --git a/server/core/helpers/custom-validators/video-captions.ts b/server/core/helpers/custom-validators/video-captions.tsindex 66e29055f3..723ef56e03 100644--- a/server/core/helpers/custom-validators/video-captions.ts+++ b/server/core/helpers/custom-validators/video-captions.ts@@ -5,7 +5,7 @@ import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_TEXT_LANGUAGES } from '../../initiimport { logger } from '../logger.js'import { exists, isFileValid } from './misc.js'-function isVideoCaptionLanguageValid (value: any) {+export function isVideoCaptionLanguageValid (value: any) {return exists(value) && VIDEO_TEXT_LANGUAGES[value] !== undefined}@@ -14,7 +14,7 @@ const videoCaptionTypesRegex = [ ...Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYP.map(m => `(${m})`).join('|')-function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {+export function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {return isFileValid({files,mimeTypeRegex: videoCaptionTypesRegex,@@ -23,7 +23,7 @@ function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {})}-async function isVTTFileValid (filePath: string) {+export async function isVTTFileValid (filePath: string) {const size = await getFileSize(filePath)const content = await readFile(filePath, 'utf8')@@ -31,13 +31,5 @@ async function isVTTFileValid (filePath: string) {if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false- return content?.startsWith('WEBVTT')-}--// -----------------------------------------------------------------------------export {- isVideoCaptionFile,- isVTTFileValid,- isVideoCaptionLanguageValid+ return !!content?.startsWith('WEBVTT')}