aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-06 17:13:39 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commitce33919c24e7402d92d81f3cd8e545df52d98240 (patch)
tree7e131a2f8df649899d0a71294665cf386ffb50d4 /server/middlewares
parent788487140c500abeb69ca44daf3a9e26efa8d36f (diff)
downloadPeerTube-ce33919c24e7402d92d81f3cd8e545df52d98240.tar.gz
PeerTube-ce33919c24e7402d92d81f3cd8e545df52d98240.tar.zst
PeerTube-ce33919c24e7402d92d81f3cd8e545df52d98240.zip
Import magnets with webtorrent
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/video-imports.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts
index d806edfa3..8ec9373fb 100644
--- a/server/middlewares/validators/video-imports.ts
+++ b/server/middlewares/validators/video-imports.ts
@@ -6,14 +6,19 @@ import { areValidationErrors } from './utils'
6import { getCommonVideoAttributes } from './videos' 6import { getCommonVideoAttributes } from './videos'
7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../helpers/utils' 8import { cleanUpReqFiles } from '../../helpers/utils'
9import { isVideoChannelOfAccountExist, 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'
11 11
12const videoImportAddValidator = getCommonVideoAttributes().concat([ 12const videoImportAddValidator = getCommonVideoAttributes().concat([
13 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
14 body('channelId') 13 body('channelId')
15 .toInt() 14 .toInt()
16 .custom(isIdValid).withMessage('Should have correct video channel id'), 15 .custom(isIdValid).withMessage('Should have correct video channel id'),
16 body('targetUrl')
17 .optional()
18 .custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
19 body('magnetUri')
20 .optional()
21 .custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'),
17 body('name') 22 body('name')
18 .optional() 23 .optional()
19 .custom(isVideoNameValid).withMessage('Should have a valid name'), 24 .custom(isVideoNameValid).withMessage('Should have a valid name'),
@@ -34,6 +39,15 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([
34 39
35 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 40 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
36 41
42 // Check we have at least 1 required param
43 if (!req.body.targetUrl && !req.body.magnetUri) {
44 cleanUpReqFiles(req)
45
46 return res.status(400)
47 .json({ error: 'Should have a magnetUri or a targetUrl.' })
48 .end()
49 }
50
37 return next() 51 return next()
38 } 52 }
39]) 53])