X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Faccount.ts;h=96e120a38506f9ba9a9a1289478a2a905ca71ff7;hb=6702a1b2ccd666285dee9c72b5bace641d2fce8b;hp=6951dfc80d6fbef8c6a9ff7cec0a1d19e70a9285;hpb=3fd3ab2d34d512b160a5e6084d7609be7b4f4452;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 6951dfc80..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 } from '../../helpers' -import { isAccountNameValid, isLocalAccountNameExist } 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 }