]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/pods.js
Server: fix makefriends validation and tests
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pods.js
index 7c4d04affc8b497cab3d2a703ed879a86543a401..3c605c45e96353f40aa12983856d1547209d8613 100644 (file)
@@ -10,23 +10,24 @@ const validatorsPod = {
 }
 
 function makeFriends (req, res, next) {
-  req.checkBody('urls', 'Should have an array of urls').isArray()
-  req.checkBody('urls', 'Should be an url').isEachUrl()
+  req.checkBody('urls', 'Should have an array of unique urls').isEachUniqueUrlValid()
 
   logger.debug('Checking makeFriends parameters', { parameters: req.body })
 
-  friends.hasFriends(function (err, hasFriends) {
-    if (err) {
-      logger.error('Cannot know if we have friends.', { error: err })
-      res.sendStatus(500)
-    }
-
-    if (hasFriends === true) {
-      // We need to quit our friends before make new ones
-      res.sendStatus(409)
-    } else {
-      return next()
-    }
+  checkErrors(req, res, function () {
+    friends.hasFriends(function (err, hasFriends) {
+      if (err) {
+        logger.error('Cannot know if we have friends.', { error: err })
+        res.sendStatus(500)
+      }
+
+      if (hasFriends === true) {
+        // We need to quit our friends before make new ones
+        res.sendStatus(409)
+      } else {
+        return next()
+      }
+    })
   })
 }