X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Faccount.ts;h=e529c831d541ea575e80209a8d6f3d623848dc00;hb=3318147300b4f998adf728eb0a5a14a4c1829c51;hp=47ed6a7bb1591ac56f7e5d9979baf3defee9fa13;hpb=4e50b6a1c9a3eb261e04ede73241648e6edf21d6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 47ed6a7bb..e529c831d 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -1,23 +1,38 @@ -import * as express from 'express' -import { param } from 'express-validator/check' -import { logger } from '../../helpers' -import { checkLocalAccountNameExists, isAccountNameValid } from '../../helpers/custom-validators/accounts' -import { checkErrors } from './utils' +import express from 'express' +import { param } from 'express-validator' +import { isAccountNameValid } from '../../helpers/custom-validators/accounts' +import { logger } from '../../helpers/logger' +import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared' const localAccountValidator = [ param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), - (req: express.Request, res: express.Response, next: express.NextFunction) => { + async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) - checkErrors(req, res, () => { - checkLocalAccountNameExists(req.params.name, res, next) - }) + if (areValidationErrors(req, 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() } ] // --------------------------------------------------------------------------- export { - localAccountValidator + localAccountValidator, + accountNameWithHostGetValidator }