Init commit
This commit is contained in:
37
server/core/middlewares/validators/webfinger.ts
Normal file
37
server/core/middlewares/validators/webfinger.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import express from 'express'
|
||||
import { query } from 'express-validator'
|
||||
import { HttpStatusCode } from '@peertube/peertube-models'
|
||||
import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger.js'
|
||||
import { getHostWithPort } from '../../helpers/express-utils.js'
|
||||
import { ActorModel } from '../../models/actor/actor.js'
|
||||
import { areValidationErrors } from './shared/index.js'
|
||||
|
||||
const webfingerValidator = [
|
||||
query('resource')
|
||||
.custom(isWebfingerLocalResourceValid),
|
||||
|
||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
if (areValidationErrors(req, res)) return
|
||||
|
||||
// Remove 'acct:' from the beginning of the string
|
||||
const handle = getHostWithPort(req.query.resource.substr(5))
|
||||
const [ name ] = handle.split('@')
|
||||
|
||||
const actor = await ActorModel.loadLocalUrlByName(name)
|
||||
if (!actor) {
|
||||
return res.fail({
|
||||
status: HttpStatusCode.NOT_FOUND_404,
|
||||
message: 'Actor not found'
|
||||
})
|
||||
}
|
||||
|
||||
res.locals.actorUrl = actor
|
||||
return next()
|
||||
}
|
||||
]
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
webfingerValidator
|
||||
}
|
||||
Reference in New Issue
Block a user