PeerTube/server/middlewares/validators/account.ts

36 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-08-27 14:32:44 +02:00
import express from 'express'
2019-07-25 16:23:44 +02:00
import { param } from 'express-validator'
2019-07-23 10:40:39 +02:00
import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'
2017-11-09 17:51:58 +01:00
const localAccountValidator = [
param('name')
.custom(isAccountNameValid),
2017-11-09 17:51:58 +01:00
2017-11-27 17:30:46 +01:00
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
2019-03-19 09:26:50 +01:00
if (!await doesLocalAccountNameExist(req.params.name, res)) return
2017-11-27 17:30:46 +01:00
return next()
2017-11-09 17:51:58 +01:00
}
]
2019-02-26 10:55:40 +01:00
const accountNameWithHostGetValidator = [
param('accountName')
.exists(),
2018-02-21 16:44:18 +01:00
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
2019-03-19 09:26:50 +01:00
if (!await doesAccountNameWithHostExist(req.params.accountName, res)) return
2018-02-21 16:44:18 +01:00
return next()
}
]
2017-11-09 17:51:58 +01:00
// ---------------------------------------------------------------------------
export {
2018-01-03 16:38:50 +01:00
localAccountValidator,
2019-02-26 10:55:40 +01:00
accountNameWithHostGetValidator
2017-11-09 17:51:58 +01:00
}