]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/webfinger.ts
Support only ffmpeg >= 4.3
[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'
7d9ba5c0 6import { ActorModel } from '../../models/actor/actor'
10363c74 7import { areValidationErrors } from './shared'
350e31d6
C
8
9const webfingerValidator = [
396f6f01
C
10 query('resource')
11 .custom(isWebfingerLocalResourceValid),
350e31d6 12
a2431b7d 13 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
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
0374b6b5 20 const actor = await ActorModel.loadLocalUrlByName(name)
50d6de9c 21 if (!actor) {
76148b27
RK
22 return res.fail({
23 status: HttpStatusCode.NOT_FOUND_404,
24 message: 'Actor not found'
25 })
a2431b7d
C
26 }
27
0374b6b5 28 res.locals.actorUrl = actor
a2431b7d 29 return next()
350e31d6
C
30 }
31]
32
33// ---------------------------------------------------------------------------
34
35export {
36 webfingerValidator
37}