]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/video-imports.ts
add user account email verificiation (#977)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / video-imports.ts
index c03cf2e4d6c4146de56c797452941f02627ccbfc..b2063b8dac1a47561f543743b8ed5e38c27800c3 100644 (file)
@@ -5,7 +5,7 @@ import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
 import { getCommonVideoAttributes } from './videos'
 import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../helpers/custom-validators/video-imports'
-import { cleanUpReqFiles } from '../../helpers/utils'
+import { cleanUpReqFiles } from '../../helpers/express-utils'
 import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../helpers/custom-validators/videos'
 import { CONFIG } from '../../initializers/constants'
 import { CONSTRAINTS_FIELDS } from '../../initializers'
@@ -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)