]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/account.ts
Refactor middleware helpers
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / account.ts
index 3573a9a5053a970a9c8abdeb1d75df51e0cd4ee1..67e4bf8cca25f3063d3f7a6e614f77025ca76a30 100644 (file)
@@ -1,8 +1,9 @@
 import * as express from 'express'
 import { param } from 'express-validator/check'
-import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
+import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
 import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
+import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares'
 
 const localAccountValidator = [
   param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
@@ -11,7 +12,20 @@ const localAccountValidator = [
     logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
 
     if (areValidationErrors(req, res)) return
-    if (!await isLocalAccountNameExist(req.params.name, res)) return
+    if (!await doesLocalAccountNameExist(req.params.name, res)) return
+
+    return next()
+  }
+]
+
+const accountNameWithHostGetValidator = [
+  param('accountName').exists().withMessage('Should have an account name with host'),
+
+  async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+    logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
+
+    if (areValidationErrors(req, res)) return
+    if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
 
     return next()
   }
@@ -20,5 +34,6 @@ const localAccountValidator = [
 // ---------------------------------------------------------------------------
 
 export {
-  localAccountValidator
+  localAccountValidator,
+  accountNameWithHostGetValidator
 }