1 import { param } from 'express-validator/check'
2 import * as express from 'express'
4 import { database as db } from '../../initializers/database'
5 import { checkErrors } from './utils'
10 isUserVideoQuotaValid,
11 isUserDisplayNSFWValid,
14 } from '../../helpers'
15 import { AccountInstance } from '../../models'
17 const localAccountValidator = [
18 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
20 (req: express.Request, res: express.Response, next: express.NextFunction) => {
21 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
23 checkErrors(req, res, () => {
24 checkLocalAccountExists(req.params.name, res, next)
29 // ---------------------------------------------------------------------------
35 // ---------------------------------------------------------------------------
37 function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) {
38 db.Account.loadLocalAccountByName(name)
41 return res.status(404)
42 .send({ error: 'Account not found' })
46 res.locals.account = account
47 return callback(null, account)
50 logger.error('Error in account request validator.', err)
51 return res.sendStatus(500)