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