aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
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