aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/video-imports.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts
index d8b9bfaff..4d6ab1fa4 100644
--- a/server/helpers/custom-validators/video-imports.ts
+++ b/server/helpers/custom-validators/video-imports.ts
@@ -1,10 +1,9 @@
1import 'express-validator' 1import 'express-validator'
2import 'multer' 2import 'multer'
3import * as validator from 'validator' 3import * as validator from 'validator'
4import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' 4import { CONSTRAINTS_FIELDS, TORRENT_MIMETYPE_EXT, VIDEO_IMPORT_STATES } from '../../initializers'
5import { exists } from './misc' 5import { exists, isFileValid } from './misc'
6import * as express from 'express' 6import * as express from 'express'
7import { VideoChannelModel } from '../../models/video/video-channel'
8import { VideoImportModel } from '../../models/video/video-import' 7import { VideoImportModel } from '../../models/video/video-import'
9 8
10function isVideoImportTargetUrlValid (url: string) { 9function isVideoImportTargetUrlValid (url: string) {
@@ -25,6 +24,12 @@ function isVideoImportStateValid (value: any) {
25 return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined 24 return exists(value) && VIDEO_IMPORT_STATES[ value ] !== undefined
26} 25}
27 26
27const videoTorrentImportTypes = Object.keys(TORRENT_MIMETYPE_EXT).map(m => `(${m})`)
28const videoTorrentImportRegex = videoTorrentImportTypes.join('|')
29function isVideoImportTorrentFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) {
30 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true)
31}
32
28async function isVideoImportExist (id: number, res: express.Response) { 33async function isVideoImportExist (id: number, res: express.Response) {
29 const videoImport = await VideoImportModel.loadAndPopulateVideo(id) 34 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
30 35
@@ -45,5 +50,6 @@ async function isVideoImportExist (id: number, res: express.Response) {
45export { 50export {
46 isVideoImportStateValid, 51 isVideoImportStateValid,
47 isVideoImportTargetUrlValid, 52 isVideoImportTargetUrlValid,
48 isVideoImportExist 53 isVideoImportExist,
54 isVideoImportTorrentFile
49} 55}