]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express from 'express' |
c8861d5d | 2 | import { query } from 'express-validator' |
c0e8b12e | 3 | import { HttpStatusCode } from '../../../shared/models/http/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' |
10363c74 | 8 | import { areValidationErrors } from './shared' |
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) { |
76148b27 RK |
24 | return res.fail({ |
25 | status: HttpStatusCode.NOT_FOUND_404, | |
26 | message: 'Actor not found' | |
27 | }) | |
a2431b7d C |
28 | } |
29 | ||
0374b6b5 | 30 | res.locals.actorUrl = actor |
a2431b7d | 31 | return next() |
350e31d6 C |
32 | } |
33 | ] | |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | export { | |
38 | webfingerValidator | |
39 | } |