You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
main
${ noResults }
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
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 nameWithHost = getHostWithPort(req.query.resource.substr(5))
|
|||
const [ name ] = nameWithHost.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
|
|||
}
|