1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00
Peertube/server/core/middlewares/validators/account.ts
2025-04-10 09:55:55 +02:00

31 lines
977 B
TypeScript

import { UserRight } from '@peertube/peertube-models'
import express from 'express'
import { param } from 'express-validator'
import { areValidationErrors, checkUserCanManageAccount, doesAccountHandleExist } from './shared/index.js'
export const accountHandleGetValidatorFactory = (options: {
checkManage: boolean
checkIsLocal: boolean
}) => {
const { checkManage, checkIsLocal } = options
return [
param('handle')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
if (!await doesAccountHandleExist({ handle: req.params.handle, res, checkIsLocal, checkManage })) return
if (options.checkManage) {
const user = res.locals.oauth.token.User
if (!checkUserCanManageAccount({ account: res.locals.account, user, res, specialRight: UserRight.MANAGE_USERS })) {
return false
}
}
return next()
}
]
}