diff options
author | Chocobozzz <me@florianbigard.com> | 2018-08-07 09:54:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-08-08 09:30:31 +0200 |
commit | 990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 (patch) | |
tree | 8aaa0638798bfa14813f4d6ed5247242313b9ce6 /server/helpers/custom-validators | |
parent | ce33919c24e7402d92d81f3cd8e545df52d98240 (diff) | |
download | PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.tar.gz PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.tar.zst PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.zip |
Import torrents with webtorrent
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 | } |