diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/video-imports.ts | 14 |
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 @@ | |||
1 | import 'express-validator' | 1 | import 'express-validator' |
2 | import 'multer' | 2 | import 'multer' |
3 | import * as validator from 'validator' | 3 | import * as validator from 'validator' |
4 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' | 4 | import { CONSTRAINTS_FIELDS, TORRENT_MIMETYPE_EXT, VIDEO_IMPORT_STATES } from '../../initializers' |
5 | import { exists } from './misc' | 5 | import { exists, isFileValid } from './misc' |
6 | import * as express from 'express' | 6 | import * as express from 'express' |
7 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
8 | import { VideoImportModel } from '../../models/video/video-import' | 7 | import { VideoImportModel } from '../../models/video/video-import' |
9 | 8 | ||
10 | function isVideoImportTargetUrlValid (url: string) { | 9 | function 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 | ||
27 | const videoTorrentImportTypes = Object.keys(TORRENT_MIMETYPE_EXT).map(m => `(${m})`) | ||
28 | const videoTorrentImportRegex = videoTorrentImportTypes.join('|') | ||
29 | function 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 | |||
28 | async function isVideoImportExist (id: number, res: express.Response) { | 33 | async 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) { | |||
45 | export { | 50 | export { |
46 | isVideoImportStateValid, | 51 | isVideoImportStateValid, |
47 | isVideoImportTargetUrlValid, | 52 | isVideoImportTargetUrlValid, |
48 | isVideoImportExist | 53 | isVideoImportExist, |
54 | isVideoImportTorrentFile | ||
49 | } | 55 | } |