]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/webfinger.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / webfinger.ts
CommitLineData
41fb13c3 1import express from 'express'
c8861d5d 2import { query } from 'express-validator'
c0e8b12e 3import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
06a05d5f 4import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'
7d9ba5c0 5import { getHostWithPort } from '../../helpers/express-utils'
da854ddd 6import { logger } from '../../helpers/logger'
7d9ba5c0 7import { ActorModel } from '../../models/actor/actor'
10363c74 8import { areValidationErrors } from './shared'
350e31d6
C
9
10const webfingerValidator = [
396f6f01
C
11 query('resource')
12 .custom(isWebfingerLocalResourceValid),
350e31d6 13
a2431b7d 14 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
350e31d6
C
15 logger.debug('Checking webfinger parameters', { parameters: req.query })
16
a2431b7d
C
17 if (areValidationErrors(req, res)) return
18
19 // Remove 'acct:' from the beginning of the string
0405ab52 20 const nameWithHost = getHostWithPort(req.query.resource.substr(5))
a2431b7d
C
21 const [ name ] = nameWithHost.split('@')
22
0374b6b5 23 const actor = await ActorModel.loadLocalUrlByName(name)
50d6de9c 24 if (!actor) {
76148b27
RK
25 return res.fail({
26 status: HttpStatusCode.NOT_FOUND_404,
27 message: 'Actor not found'
28 })
a2431b7d
C
29 }
30
0374b6b5 31 res.locals.actorUrl = actor
a2431b7d 32 return next()
350e31d6
C
33 }
34]
35
36// ---------------------------------------------------------------------------
37
38export {
39 webfingerValidator
40}