1 import * as express from 'express'
2 import { param } from 'express-validator/check'
4 isUserDisplayNSFWValid,
10 } from '../../helpers'
11 import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
12 import { database as db } from '../../initializers/database'
13 import { AccountInstance } from '../../models'
14 import { checkErrors } from './utils'
16 const localAccountValidator = [
17 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
19 (req: express.Request, res: express.Response, next: express.NextFunction) => {
20 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
22 checkErrors(req, res, () => {
23 checkLocalAccountExists(req.params.name, res, next)
28 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) {
37 db.Account.loadLocalByName(name)
40 return res.status(404)
41 .send({ error: 'Account not found' })
45 res.locals.account = account
46 return callback(null, account)
49 logger.error('Error in account request validator.', err)
50 return res.sendStatus(500)