]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/video-captions.ts
Fix peertube subtitles import
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-captions.ts
index d5b09ea03628a998a921958bb72fec5c20c572b4..0e24655a081a793864a6890c5375bd0cdecd6fed 100644 (file)
@@ -2,6 +2,7 @@ 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) {
@@ -24,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')
 }
 
 // ---------------------------------------------------------------------------