]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/account.ts
Fix socket notification with multiple user tabs
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / account.ts
CommitLineData
e4f97bab 1import * as express from 'express'
c8861d5d 2import { param } from 'express-validator'
3e753302 3import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
da854ddd 4import { logger } from '../../helpers/logger'
a2431b7d 5import { areValidationErrors } from './utils'
3e753302 6import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares'
e4f97bab
C
7
8const localAccountValidator = [
350e31d6 9 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
e4f97bab 10
a2431b7d 11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
e4f97bab
C
12 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
13
a2431b7d 14 if (areValidationErrors(req, res)) return
0f6acda1 15 if (!await doesLocalAccountNameExist(req.params.name, res)) return
a2431b7d
C
16
17 return next()
e4f97bab
C
18 }
19]
20
418d092a 21const accountNameWithHostGetValidator = [
ad9e39fb 22 param('accountName').exists().withMessage('Should have an account name with host'),
e8cb4409
C
23
24 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
25 logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })
26
27 if (areValidationErrors(req, res)) return
0f6acda1 28 if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
e8cb4409
C
29
30 return next()
31 }
32]
33
e4f97bab
C
34// ---------------------------------------------------------------------------
35
36export {
265ba139 37 localAccountValidator,
418d092a 38 accountNameWithHostGetValidator
e4f97bab 39}