2
1

webfinger.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import * as express from 'express'
  2. import { query } from 'express-validator/check'
  3. import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'
  4. import { logger } from '../../helpers/logger'
  5. import { ActorModel } from '../../models/activitypub/actor'
  6. import { areValidationErrors } from './utils'
  7. import { getHostWithPort } from '../../helpers/express-utils'
  8. const webfingerValidator = [
  9. query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'),
  10. async (req: express.Request, res: express.Response, next: express.NextFunction) => {
  11. logger.debug('Checking webfinger parameters', { parameters: req.query })
  12. if (areValidationErrors(req, res)) return
  13. // Remove 'acct:' from the beginning of the string
  14. const nameWithHost = getHostWithPort(req.query.resource.substr(5))
  15. const [ name ] = nameWithHost.split('@')
  16. const actor = await ActorModel.loadLocalByName(name)
  17. if (!actor) {
  18. return res.status(404)
  19. .send({ error: 'Actor not found' })
  20. .end()
  21. }
  22. res.locals.actor = actor
  23. return next()
  24. }
  25. ]
  26. // ---------------------------------------------------------------------------
  27. export {
  28. webfingerValidator
  29. }