]>
Commit | Line | Data |
---|---|---|
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 { removeRedundancyOf } from '../../../lib/redundancy' | |
6 | import { logger } from '../../../helpers/logger' | |
7 | ||
8 | const serverRedundancyRouter = express.Router() | |
9 | ||
10 | serverRedundancyRouter.put('/redundancy/:host', | |
11 | authenticate, | |
12 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | |
13 | asyncMiddleware(updateServerRedundancyValidator), | |
14 | asyncMiddleware(updateRedundancy) | |
15 | ) | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | export { | |
20 | serverRedundancyRouter | |
21 | } | |
22 | ||
23 | // --------------------------------------------------------------------------- | |
24 | ||
25 | async function updateRedundancy (req: express.Request, res: express.Response) { | |
26 | const server = res.locals.server | |
27 | ||
28 | server.redundancyAllowed = req.body.redundancyAllowed | |
29 | ||
30 | await server.save() | |
31 | ||
32 | // Async, could be long | |
33 | removeRedundancyOf(server.id) | |
34 | .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err)) | |
35 | ||
36 | return res.sendStatus(204) | |
37 | } |