]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/validators/account.ts
Split ffmpeg utils with ffprobe utils
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / account.ts
... / ...
CommitLineData
1import * as express from 'express'
2import { param } from 'express-validator'
3import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils'
6import { doesAccountNameWithHostExist, doesLocalAccountNameExist } from '../../helpers/middlewares'
7
8const localAccountValidator = [
9 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
10
11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
13
14 if (areValidationErrors(req, res)) return
15 if (!await doesLocalAccountNameExist(req.params.name, res)) return
16
17 return next()
18 }
19]
20
21const accountNameWithHostGetValidator = [
22 param('accountName').exists().withMessage('Should have an account name with host'),
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
28 if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
29
30 return next()
31 }
32]
33
34// ---------------------------------------------------------------------------
35
36export {
37 localAccountValidator,
38 accountNameWithHostGetValidator
39}