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