X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideo-captions.ts;h=0e24655a081a793864a6890c5375bd0cdecd6fed;hb=c56dd2807fe5d129907b9bf8c42656a8314d754b;hp=59ba005fe3f4b8d8feb152b9e210b559c72feac5;hpb=7b51ede977c299a74728171d8c124bcc4cbba6ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 59ba005fe..0e24655a0 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts @@ -2,16 +2,18 @@ import { UploadFilesForCheck } from 'express' import { readFile } from 'fs-extra' import { getFileSize } from '@shared/extra-utils' import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' +import { logger } from '../logger' import { exists, isFileValid } from './misc' function isVideoCaptionLanguageValid (value: any) { return exists(value) && VIDEO_LANGUAGES[value] !== undefined } -const videoCaptionTypesRegex = Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT) - .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream - .map(m => `(${m})`) - .join('|') +// MacOS sends application/octet-stream +const videoCaptionTypesRegex = [ ...Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT), 'application/octet-stream' ] + .map(m => `(${m})`) + .join('|') + function isVideoCaptionFile (files: UploadFilesForCheck, field: string) { return isFileValid({ files, @@ -23,12 +25,13 @@ function isVideoCaptionFile (files: UploadFilesForCheck, field: string) { async function isVTTFileValid (filePath: string) { const size = await getFileSize(filePath) + const content = await readFile(filePath, 'utf8') - if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false + logger.debug('Checking VTT file %s', filePath, { size, content }) - const content = await readFile(filePath, 'utf8') + if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false - return content?.startsWith('WEBVTT\n') + return content?.startsWith('WEBVTT') } // ---------------------------------------------------------------------------