aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-captions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/video-captions.ts')
-rw-r--r--server/helpers/custom-validators/video-captions.ts43
1 files changed, 0 insertions, 43 deletions
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts
deleted file mode 100644
index 0e24655a0..000000000
--- a/server/helpers/custom-validators/video-captions.ts
+++ /dev/null
@@ -1,43 +0,0 @@
1import { UploadFilesForCheck } from 'express'
2import { readFile } from 'fs-extra'
3import { getFileSize } from '@shared/extra-utils'
4import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants'
5import { logger } from '../logger'
6import { exists, isFileValid } from './misc'
7
8function isVideoCaptionLanguageValid (value: any) {
9 return exists(value) && VIDEO_LANGUAGES[value] !== undefined
10}
11
12// MacOS sends application/octet-stream
13const videoCaptionTypesRegex = [ ...Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYPE_EXT), 'application/octet-stream' ]
14 .map(m => `(${m})`)
15 .join('|')
16
17function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {
18 return isFileValid({
19 files,
20 mimeTypeRegex: videoCaptionTypesRegex,
21 field,
22 maxSize: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max
23 })
24}
25
26async function isVTTFileValid (filePath: string) {
27 const size = await getFileSize(filePath)
28 const content = await readFile(filePath, 'utf8')
29
30 logger.debug('Checking VTT file %s', filePath, { size, content })
31
32 if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false
33
34 return content?.startsWith('WEBVTT')
35}
36
37// ---------------------------------------------------------------------------
38
39export {
40 isVideoCaptionFile,
41 isVTTFileValid,
42 isVideoCaptionLanguageValid
43}