]>
Commit | Line | Data |
---|---|---|
350e31d6 | 1 | import * as express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
06a05d5f | 3 | import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' |
da854ddd | 4 | import { logger } from '../../helpers/logger' |
50d6de9c | 5 | import { ActorModel } from '../../models/activitypub/actor' |
a2431b7d | 6 | import { areValidationErrors } from './utils' |
0626e7af | 7 | import { getHostWithPort } from '../../helpers/express-utils' |
350e31d6 C |
8 | |
9 | const webfingerValidator = [ | |
06a05d5f | 10 | query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'), |
350e31d6 | 11 | |
a2431b7d | 12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
350e31d6 C |
13 | logger.debug('Checking webfinger parameters', { parameters: req.query }) |
14 | ||
a2431b7d C |
15 | if (areValidationErrors(req, res)) return |
16 | ||
17 | // Remove 'acct:' from the beginning of the string | |
0405ab52 | 18 | const nameWithHost = getHostWithPort(req.query.resource.substr(5)) |
a2431b7d C |
19 | const [ name ] = nameWithHost.split('@') |
20 | ||
0374b6b5 | 21 | const actor = await ActorModel.loadLocalUrlByName(name) |
50d6de9c | 22 | if (!actor) { |
a2431b7d | 23 | return res.status(404) |
50d6de9c | 24 | .send({ error: 'Actor not found' }) |
a2431b7d C |
25 | .end() |
26 | } | |
27 | ||
0374b6b5 | 28 | res.locals.actorUrl = actor |
a2431b7d | 29 | return next() |
350e31d6 C |
30 | } |
31 | ] | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | export { | |
36 | webfingerValidator | |
37 | } |