1
0
Fork 0
peertube/server/middlewares/validators/account.ts

39 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-11-09 11:51:58 -05:00
import * as express from 'express'
2017-11-13 11:39:41 -05:00
import { param } from 'express-validator/check'
2019-03-19 04:26:50 -04:00
import { isAccountNameValid, doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
2017-12-28 05:16:08 -05:00
import { logger } from '../../helpers/logger'
2017-11-27 11:30:46 -05:00
import { areValidationErrors } from './utils'
2017-11-09 11:51:58 -05:00
const localAccountValidator = [
2017-11-14 11:31:26 -05:00
param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
2017-11-09 11:51:58 -05:00
2017-11-27 11:30:46 -05:00
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
2017-11-09 11:51:58 -05:00
logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
2017-11-27 11:30:46 -05:00
if (areValidationErrors(req, res)) return
2019-03-19 04:26:50 -04:00
if (!await doesLocalAccountNameExist(req.params.name, res)) return
2017-11-27 11:30:46 -05:00
return next()
2017-11-09 11:51:58 -05:00
}
]
2019-02-26 04:55:40 -05:00
const accountNameWithHostGetValidator = [
2018-05-25 03:57:16 -04:00
param('accountName').exists().withMessage('Should have an account name with host'),
2018-02-21 10:44:18 -05:00
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
if (areValidationErrors(req, res)) return
2019-03-19 04:26:50 -04:00
if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
2018-02-21 10:44:18 -05:00
return next()
}
]
2017-11-09 11:51:58 -05:00
// ---------------------------------------------------------------------------
export {
2018-01-03 10:38:50 -05:00
localAccountValidator,
2019-02-26 04:55:40 -05:00
accountNameWithHostGetValidator
2017-11-09 11:51:58 -05:00
}