X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Faccount.ts;h=96e120a38506f9ba9a9a1289478a2a905ca71ff7;hb=2ba92871319d7af63472c1380664a9f9eeb1c690;hp=70f4e4d3bc5e33a17b4adcc05ead4de5aac526d1;hpb=a2431b7dcbc72c05101dcdbe631ff84a823aeb51;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 70f4e4d3b..96e120a38 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { param } from 'express-validator/check' -import { logger, isLocalAccountNameExist } from '../../helpers' -import { isAccountNameValid } from '../../helpers/custom-validators/accounts' +import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts' +import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' const localAccountValidator = [ @@ -11,7 +11,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 +33,6 @@ const localAccountValidator = [ // --------------------------------------------------------------------------- export { - localAccountValidator + localAccountValidator, + accountNameWithHostGetValidator }