1 import * as express from 'express'
2 import { UserRight } from '../../../../shared/models/users'
3 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
4 import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy'
5 import { ServerModel } from '../../../models/server/server'
6 import { removeRedundancyOf } from '../../../lib/redundancy'
7 import { logger } from '../../../helpers/logger'
9 const serverRedundancyRouter = express.Router()
11 serverRedundancyRouter.put('/redundancy/:host',
13 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
14 asyncMiddleware(updateServerRedundancyValidator),
15 asyncMiddleware(updateRedundancy)
18 // ---------------------------------------------------------------------------
21 serverRedundancyRouter
24 // ---------------------------------------------------------------------------
26 async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {
27 const server = res.locals.server as ServerModel
29 server.redundancyAllowed = req.body.redundancyAllowed
33 // Async, could be long
34 removeRedundancyOf(server.id)
35 .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err))
37 return res.sendStatus(204)