diff options
Diffstat (limited to 'server/helpers/custom-validators/video-imports.ts')
-rw-r--r-- | server/helpers/custom-validators/video-imports.ts | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts deleted file mode 100644 index da8962cb6..000000000 --- a/server/helpers/custom-validators/video-imports.ts +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | import 'multer' | ||
2 | import { UploadFilesForCheck } from 'express' | ||
3 | import validator from 'validator' | ||
4 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initializers/constants' | ||
5 | import { exists, isFileValid } from './misc' | ||
6 | |||
7 | function isVideoImportTargetUrlValid (url: string) { | ||
8 | const isURLOptions = { | ||
9 | require_host: true, | ||
10 | require_tld: true, | ||
11 | require_protocol: true, | ||
12 | require_valid_protocol: true, | ||
13 | protocols: [ 'http', 'https' ] | ||
14 | } | ||
15 | |||
16 | return exists(url) && | ||
17 | validator.isURL('' + url, isURLOptions) && | ||
18 | validator.isLength('' + url, CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL) | ||
19 | } | ||
20 | |||
21 | function isVideoImportStateValid (value: any) { | ||
22 | return exists(value) && VIDEO_IMPORT_STATES[value] !== undefined | ||
23 | } | ||
24 | |||
25 | // MacOS sends application/octet-stream | ||
26 | const videoTorrentImportRegex = [ ...Object.keys(MIMETYPES.TORRENT.MIMETYPE_EXT), 'application/octet-stream' ] | ||
27 | .map(m => `(${m})`) | ||
28 | .join('|') | ||
29 | |||
30 | function isVideoImportTorrentFile (files: UploadFilesForCheck) { | ||
31 | return isFileValid({ | ||
32 | files, | ||
33 | mimeTypeRegex: videoTorrentImportRegex, | ||
34 | field: 'torrentfile', | ||
35 | maxSize: CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.FILE_SIZE.max, | ||
36 | optional: true | ||
37 | }) | ||
38 | } | ||
39 | |||
40 | // --------------------------------------------------------------------------- | ||
41 | |||
42 | export { | ||
43 | isVideoImportStateValid, | ||
44 | isVideoImportTargetUrlValid, | ||
45 | isVideoImportTorrentFile | ||
46 | } | ||