diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/video-captions.ts | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index d5b09ea03..0e24655a0 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -2,6 +2,7 @@ import { UploadFilesForCheck } from 'express' | |||
2 | import { readFile } from 'fs-extra' | 2 | import { readFile } from 'fs-extra' |
3 | import { getFileSize } from '@shared/extra-utils' | 3 | import { getFileSize } from '@shared/extra-utils' |
4 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' |
5 | import { logger } from '../logger' | ||
5 | import { exists, isFileValid } from './misc' | 6 | import { exists, isFileValid } from './misc' |
6 | 7 | ||
7 | function isVideoCaptionLanguageValid (value: any) { | 8 | function isVideoCaptionLanguageValid (value: any) { |
@@ -24,12 +25,13 @@ function isVideoCaptionFile (files: UploadFilesForCheck, field: string) { | |||
24 | 25 | ||
25 | async function isVTTFileValid (filePath: string) { | 26 | async function isVTTFileValid (filePath: string) { |
26 | const size = await getFileSize(filePath) | 27 | const size = await getFileSize(filePath) |
28 | const content = await readFile(filePath, 'utf8') | ||
27 | 29 | ||
28 | if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false | 30 | logger.debug('Checking VTT file %s', filePath, { size, content }) |
29 | 31 | ||
30 | const content = await readFile(filePath, 'utf8') | 32 | if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false |
31 | 33 | ||
32 | return content?.startsWith('WEBVTT\n') | 34 | return content?.startsWith('WEBVTT') |
33 | } | 35 | } |
34 | 36 | ||
35 | // --------------------------------------------------------------------------- | 37 | // --------------------------------------------------------------------------- |