From ce33919c24e7402d92d81f3cd8e545df52d98240 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 6 Aug 2018 17:13:39 +0200 Subject: Import magnets with webtorrent --- server/middlewares/validators/video-imports.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators') 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' import { getCommonVideoAttributes } from './videos' import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' import { cleanUpReqFiles } from '../../helpers/utils' -import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' +import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../helpers/custom-validators/videos' import { CONFIG } from '../../initializers/constants' const videoImportAddValidator = getCommonVideoAttributes().concat([ - body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), body('channelId') .toInt() .custom(isIdValid).withMessage('Should have correct video channel id'), + body('targetUrl') + .optional() + .custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), + body('magnetUri') + .optional() + .custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'), body('name') .optional() .custom(isVideoNameValid).withMessage('Should have a valid name'), @@ -34,6 +39,15 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([ if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) + // Check we have at least 1 required param + if (!req.body.targetUrl && !req.body.magnetUri) { + cleanUpReqFiles(req) + + return res.status(400) + .json({ error: 'Should have a magnetUri or a targetUrl.' }) + .end() + } + return next() } ]) -- cgit v1.2.3