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 { logger } from '../../helpers/logger'
7 import { ActorModel } from '../../models/actor/actor'
8 import { areValidationErrors } from './shared'
10 const webfingerValidator = [
12 .custom(isWebfingerLocalResourceValid),
14 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 logger.debug('Checking webfinger parameters', { parameters: req.query })
17 if (areValidationErrors(req, res)) return
19 // Remove 'acct:' from the beginning of the string
20 const nameWithHost = getHostWithPort(req.query.resource.substr(5))
21 const [ name ] = nameWithHost.split('@')
23 const actor = await ActorModel.loadLocalUrlByName(name)
26 status: HttpStatusCode.NOT_FOUND_404,
27 message: 'Actor not found'
31 res.locals.actorUrl = actor
36 // ---------------------------------------------------------------------------