2 import validator from 'validator'
3 import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants'
4 import { exists, isFileValid } from './misc'
6 function isVideoImportTargetUrlValid (url: string) {
10 require_protocol: true,
11 require_valid_protocol: true,
12 protocols: [ 'http', 'https' ]
16 validator.isURL('' + url, isURLOptions) &&
17 validator.isLength('' + url, CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL)
20 function isVideoImportStateValid (value: any) {
21 return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined
24 const videoTorrentImportRegex = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT)
25 .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream
28 function isVideoImportTorrentFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) {
29 return isFileValid(files, videoTorrentImportRegex, 'torrentfile', CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, true)
32 // ---------------------------------------------------------------------------
35 isVideoImportStateValid,
36 isVideoImportTargetUrlValid,
37 isVideoImportTorrentFile