aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-captions.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-02-09 08:58:40 +0100
committerChocobozzz <me@florianbigard.com>2022-02-09 11:54:18 +0100
commit474542d7ac60f7860daf9ea34d1c31968f43ab29 (patch)
treec3e19095e19930d3955ce8d56d8c099bdda17923 /server/helpers/custom-validators/video-captions.ts
parentba8a8367e7fde7915ae6633445bf46ebf4a9fe94 (diff)
downloadPeerTube-474542d7ac60f7860daf9ea34d1c31968f43ab29.tar.gz
PeerTube-474542d7ac60f7860daf9ea34d1c31968f43ab29.tar.zst
PeerTube-474542d7ac60f7860daf9ea34d1c31968f43ab29.zip
Add additional checks when importing a video
Diffstat (limited to 'server/helpers/custom-validators/video-captions.ts')
-rw-r--r--server/helpers/custom-validators/video-captions.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts
index 528edf60c..4cc7dcaf4 100644
--- a/server/helpers/custom-validators/video-captions.ts
+++ b/server/helpers/custom-validators/video-captions.ts
@@ -1,3 +1,5 @@
1import { getFileSize } from '@shared/extra-utils'
2import { readFile } from 'fs-extra'
1import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' 3import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants'
2import { exists, isFileValid } from './misc' 4import { exists, isFileValid } from './misc'
3 5
@@ -13,9 +15,20 @@ function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File
13 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) 15 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
14} 16}
15 17
18async function isVTTFileValid (filePath: string) {
19 const size = await getFileSize(filePath)
20
21 if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false
22
23 const content = await readFile(filePath, 'utf8')
24
25 return content?.startsWith('WEBVTT\n')
26}
27
16// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
17 29
18export { 30export {
19 isVideoCaptionFile, 31 isVideoCaptionFile,
32 isVTTFileValid,
20 isVideoCaptionLanguageValid 33 isVideoCaptionLanguageValid
21} 34}