aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/webfinger.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/webfinger.ts')
-rw-r--r--server/middlewares/validators/webfinger.ts42
1 files changed, 18 insertions, 24 deletions
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 7852c1c2b..34e62c66d 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -1,37 +1,31 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' 3import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
4import { database as db } from '../../initializers'
5import { checkErrors } from './utils'
6import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { database as db } from '../../initializers'
6import { areValidationErrors } from './utils'
7 7
8const webfingerValidator = [ 8const webfingerValidator = [
9 query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'), 9 query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'),
10 10
11 (req: express.Request, res: express.Response, next: express.NextFunction) => { 11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
12 logger.debug('Checking webfinger parameters', { parameters: req.query }) 12 logger.debug('Checking webfinger parameters', { parameters: req.query })
13 13
14 checkErrors(req, res, () => { 14 if (areValidationErrors(req, res)) return
15 // Remove 'acct:' from the beginning of the string 15
16 const nameWithHost = req.query.resource.substr(5) 16 // Remove 'acct:' from the beginning of the string
17 const [ name ] = nameWithHost.split('@') 17 const nameWithHost = req.query.resource.substr(5)
18 18 const [ name ] = nameWithHost.split('@')
19 db.Account.loadLocalByName(name) 19
20 .then(account => { 20 const account = await db.Account.loadLocalByName(name)
21 if (!account) { 21 if (!account) {
22 return res.status(404) 22 return res.status(404)
23 .send({ error: 'Account not found' }) 23 .send({ error: 'Account not found' })
24 .end() 24 .end()
25 } 25 }
26 26
27 res.locals.account = account 27 res.locals.account = account
28 return next() 28 return next()
29 })
30 .catch(err => {
31 logger.error('Error in webfinger validator.', err)
32 return res.sendStatus(500)
33 })
34 })
35 } 29 }
36] 30]
37 31