]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/webfinger.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / webfinger.ts
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'
9
10 const webfingerValidator = [
11 query('resource')
12 .custom(isWebfingerLocalResourceValid),
13
14 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
15 logger.debug('Checking webfinger parameters', { parameters: req.query })
16
17 if (areValidationErrors(req, res)) return
18
19 // Remove 'acct:' from the beginning of the string
20 const nameWithHost = getHostWithPort(req.query.resource.substr(5))
21 const [ name ] = nameWithHost.split('@')
22
23 const actor = await ActorModel.loadLocalUrlByName(name)
24 if (!actor) {
25 return res.fail({
26 status: HttpStatusCode.NOT_FOUND_404,
27 message: 'Actor not found'
28 })
29 }
30
31 res.locals.actorUrl = actor
32 return next()
33 }
34 ]
35
36 // ---------------------------------------------------------------------------
37
38 export {
39 webfingerValidator
40 }