1 import * as express from 'express'
2 import { query } from 'express-validator/check'
3 import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
4 import { database as db } from '../../initializers'
5 import { checkErrors } from './utils'
6 import { logger } from '../../helpers/logger'
8 const webfingerValidator = [
9 query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'),
11 (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 logger.debug('Checking webfinger parameters', { parameters: req.query })
14 checkErrors(req, res, () => {
15 // Remove 'acct:' from the beginning of the string
16 const nameWithHost = req.query.resource.substr(5)
17 const [ name ] = nameWithHost.split('@')
19 db.Account.loadLocalByName(name)
22 return res.status(404)
23 .send({ error: 'Account not found' })
27 res.locals.account = account
31 logger.error('Error in webfinger validator.', err)
32 return res.sendStatus(500)
38 // ---------------------------------------------------------------------------