]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/webfinger.ts
Send video comment comments to followers/origin
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / webfinger.ts
CommitLineData
350e31d6 1import * as express from 'express'
8d468a16 2import { query } from 'express-validator/check'
0405ab52 3import { getHostWithPort, logger } from '../../helpers'
8d468a16 4import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
50d6de9c 5import { ActorModel } from '../../models/activitypub/actor'
a2431b7d 6import { areValidationErrors } from './utils'
350e31d6
C
7
8const webfingerValidator = [
9 query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'),
10
a2431b7d 11 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
350e31d6
C
12 logger.debug('Checking webfinger parameters', { parameters: req.query })
13
a2431b7d
C
14 if (areValidationErrors(req, res)) return
15
16 // Remove 'acct:' from the beginning of the string
0405ab52 17 const nameWithHost = getHostWithPort(req.query.resource.substr(5))
a2431b7d
C
18 const [ name ] = nameWithHost.split('@')
19
50d6de9c
C
20 const actor = await ActorModel.loadLocalByName(name)
21 if (!actor) {
a2431b7d 22 return res.status(404)
50d6de9c 23 .send({ error: 'Actor not found' })
a2431b7d
C
24 .end()
25 }
26
50d6de9c 27 res.locals.actor = actor
a2431b7d 28 return next()
350e31d6
C
29 }
30]
31
32// ---------------------------------------------------------------------------
33
34export {
35 webfingerValidator
36}