X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Faccount.ts;h=67e4bf8cca25f3063d3f7a6e614f77025ca76a30;hb=3e753302d8c911b59971c16a8018df0e1ab78465;hp=3573a9a5053a970a9c8abdeb1d75df51e0cd4ee1;hpb=da854ddd502cd70685ef779c673b9e63757b8aa0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 3573a9a50..67e4bf8cc 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -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 }