+const unblockAccountByServerValidator = [
+ param('accountName').exists().withMessage('Should have an account name with host'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+ if (!await isAccountNameWithHostExist(req.params.accountName, res)) return
+
+ const serverActor = await getServerActor()
+ const targetAccount = res.locals.account
+ if (!await isUnblockAccountExists(serverActor.Account.id, targetAccount.id, res)) return
+
+ return next()
+ }
+]
+
+const blockServerValidator = [
+ body('host').custom(isHostValid).withMessage('Should have a valid host'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking serverGetValidator parameters', { parameters: req.body })
+
+ if (areValidationErrors(req, res)) return
+
+ const host: string = req.body.host
+
+ if (host === CONFIG.WEBSERVER.HOST) {
+ return res.status(409)
+ .send({ error: 'You cannot block your own server.' })
+ .end()
+ }
+
+ const server = await ServerModel.loadByHost(host)
+ if (!server) {
+ return res.status(404)
+ .send({ error: 'Server host not found.' })
+ .end()
+ }
+
+ res.locals.server = server
+
+ return next()
+ }
+]
+