aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-07 09:54:36 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commit990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 (patch)
tree8aaa0638798bfa14813f4d6ed5247242313b9ce6 /server/middlewares/validators
parentce33919c24e7402d92d81f3cd8e545df52d98240 (diff)
downloadPeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.tar.gz
PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.tar.zst
PeerTube-990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66.zip
Import torrents with webtorrent
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/video-imports.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts
index 8ec9373fb..c03cf2e4d 100644
--- a/server/middlewares/validators/video-imports.ts
+++ b/server/middlewares/validators/video-imports.ts
@@ -4,10 +4,11 @@ import { isIdValid } from '../../helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6import { getCommonVideoAttributes } from './videos' 6import { getCommonVideoAttributes } from './videos'
7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../helpers/utils' 8import { cleanUpReqFiles } from '../../helpers/utils'
9import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../helpers/custom-validators/videos' 9import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../helpers/custom-validators/videos'
10import { CONFIG } from '../../initializers/constants' 10import { CONFIG } from '../../initializers/constants'
11import { CONSTRAINTS_FIELDS } from '../../initializers'
11 12
12const videoImportAddValidator = getCommonVideoAttributes().concat([ 13const videoImportAddValidator = getCommonVideoAttributes().concat([
13 body('channelId') 14 body('channelId')
@@ -19,6 +20,11 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([
19 body('magnetUri') 20 body('magnetUri')
20 .optional() 21 .optional()
21 .custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'), 22 .custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'),
23 body('torrentfile')
24 .custom((value, { req }) => isVideoImportTorrentFile(req.files)).withMessage(
25 'This torrent file is not supported or too large. Please, make sure it is of the following type: '
26 + CONSTRAINTS_FIELDS.VIDEO_IMPORTS.TORRENT_FILE.EXTNAME.join(', ')
27 ),
22 body('name') 28 body('name')
23 .optional() 29 .optional()
24 .custom(isVideoNameValid).withMessage('Should have a valid name'), 30 .custom(isVideoNameValid).withMessage('Should have a valid name'),
@@ -40,11 +46,12 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([
40 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 46 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
41 47
42 // Check we have at least 1 required param 48 // Check we have at least 1 required param
43 if (!req.body.targetUrl && !req.body.magnetUri) { 49 const file = req.files['torrentfile'][0]
50 if (!req.body.targetUrl && !req.body.magnetUri && !file) {
44 cleanUpReqFiles(req) 51 cleanUpReqFiles(req)
45 52
46 return res.status(400) 53 return res.status(400)
47 .json({ error: 'Should have a magnetUri or a targetUrl.' }) 54 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' })
48 .end() 55 .end()
49 } 56 }
50 57