1 import express from 'express'
2 import { query } from 'express-validator'
3 import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
4 import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'
5 import { getHostWithPort } from '../../helpers/express-utils'
6 import { ActorModel } from '../../models/actor/actor'
7 import { areValidationErrors } from './shared'
9 const webfingerValidator = [
11 .custom(isWebfingerLocalResourceValid),
13 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
14 if (areValidationErrors(req, res)) return
16 // Remove 'acct:' from the beginning of the string
17 const nameWithHost = getHostWithPort(req.query.resource.substr(5))
18 const [ name ] = nameWithHost.split('@')
20 const actor = await ActorModel.loadLocalUrlByName(name)
23 status: HttpStatusCode.NOT_FOUND_404,
24 message: 'Actor not found'
28 res.locals.actorUrl = actor
33 // ---------------------------------------------------------------------------