]>
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' |
7d9ba5c0 | 6 | import { ActorModel } from '../../models/actor/actor' |
10363c74 | 7 | import { areValidationErrors } from './shared' |
350e31d6 C |
8 | |
9 | const webfingerValidator = [ | |
396f6f01 C |
10 | query('resource') |
11 | .custom(isWebfingerLocalResourceValid), | |
350e31d6 | 12 | |
a2431b7d | 13 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
a2431b7d C |
14 | if (areValidationErrors(req, res)) return |
15 | ||
16 | // Remove 'acct:' from the beginning of the string | |
0405ab52 | 17 | const nameWithHost = getHostWithPort(req.query.resource.substr(5)) |
a2431b7d C |
18 | const [ name ] = nameWithHost.split('@') |
19 | ||
0374b6b5 | 20 | const actor = await ActorModel.loadLocalUrlByName(name) |
50d6de9c | 21 | if (!actor) { |
76148b27 RK |
22 | return res.fail({ |
23 | status: HttpStatusCode.NOT_FOUND_404, | |
24 | message: 'Actor not found' | |
25 | }) | |
a2431b7d C |
26 | } |
27 | ||
0374b6b5 | 28 | res.locals.actorUrl = actor |
a2431b7d | 29 | return next() |
350e31d6 C |
30 | } |
31 | ] | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | export { | |
36 | webfingerValidator | |
37 | } |