2018-08-02 09:34:09 -04:00
|
|
|
import 'multer'
|
2022-02-11 04:51:33 -05:00
|
|
|
import { UploadFilesForCheck } from 'express'
|
2020-01-07 08:56:07 -05:00
|
|
|
import validator from 'validator'
|
2019-04-11 08:26:41 -04:00
|
|
|
import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants'
|
2018-08-07 03:54:36 -04:00
|
|
|
import { exists, isFileValid } from './misc'
|
2018-08-02 09:34:09 -04:00
|
|
|
|
|
|
|
function isVideoImportTargetUrlValid (url: string) {
|
|
|
|
const isURLOptions = {
|
|
|
|
require_host: true,
|
|
|
|
require_tld: true,
|
|
|
|
require_protocol: true,
|
|
|
|
require_valid_protocol: true,
|
|
|
|
protocols: [ 'http', 'https' ]
|
|
|
|
}
|
|
|
|
|
|
|
|
return exists(url) &&
|
|
|
|
validator.isURL('' + url, isURLOptions) &&
|
|
|
|
validator.isLength('' + url, CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoImportStateValid (value: any) {
|
2020-01-31 10:56:52 -05:00
|
|
|
return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined
|
2018-08-02 09:34:09 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 04:40:52 -04:00
|
|
|
const videoTorrentImportRegex = Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT)
|
|
|
|
.concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream
|
|
|
|
.map(m => `(${m})`)
|
|
|
|
.join('|')
|
2022-02-11 04:51:33 -05:00
|
|
|
function isVideoImportTorrentFile (files: UploadFilesForCheck) {
|
|
|
|
return isFileValid({
|
|
|
|
files,
|
|
|
|
mimeTypeRegex: videoTorrentImportRegex,
|
|
|
|
field: 'torrentfile',
|
|
|
|
maxSize: CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max,
|
|
|
|
optional: true
|
|
|
|
})
|
2018-08-07 03:54:36 -04:00
|
|
|
}
|
|
|
|
|
2018-08-02 09:34:09 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isVideoImportStateValid,
|
2018-08-02 10:33:29 -04:00
|
|
|
isVideoImportTargetUrlValid,
|
2018-08-07 03:54:36 -04:00
|
|
|
isVideoImportTorrentFile
|
2018-08-02 09:34:09 -04:00
|
|
|
}
|