From a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Aug 2018 10:07:53 +0200 Subject: Add import.video.torrent configuration --- server/middlewares/validators/config.ts | 1 + server/middlewares/validators/video-imports.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 9d303eee2..f3f257d57 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts @@ -25,6 +25,7 @@ const customConfigUpdateValidator = [ body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), + body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts index c03cf2e4d..9ac739101 100644 --- a/server/middlewares/validators/video-imports.ts +++ b/server/middlewares/validators/video-imports.ts @@ -33,21 +33,28 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([ logger.debug('Checking videoImportAddValidator parameters', { parameters: req.body }) const user = res.locals.oauth.token.User + const torrentFile = req.files && req.files['torrentfile'] ? req.files['torrentfile'][0] : undefined if (areValidationErrors(req, res)) return cleanUpReqFiles(req) - if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) { + if (req.body.targetUrl && CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) { cleanUpReqFiles(req) return res.status(409) - .json({ error: 'Import is not enabled on this instance.' }) + .json({ error: 'HTTP import is not enabled on this instance.' }) .end() } + if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) { + cleanUpReqFiles(req) + return res.status(409) + .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' }) + .end() + } + if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) // Check we have at least 1 required param - const file = req.files['torrentfile'][0] - if (!req.body.targetUrl && !req.body.magnetUri && !file) { + if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) { cleanUpReqFiles(req) return res.status(400) -- cgit v1.2.3