]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/server/redundancy.ts
4216b9e353835c57c46641c2ec757bd01b87f488
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / redundancy.ts
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
7 const serverRedundancyRouter = express.Router()
8
9 serverRedundancyRouter.put('/redundancy/:host',
10 authenticate,
11 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
12 asyncMiddleware(updateServerRedundancyValidator),
13 asyncMiddleware(updateRedundancy)
14 )
15
16 // ---------------------------------------------------------------------------
17
18 export {
19 serverRedundancyRouter
20 }
21
22 // ---------------------------------------------------------------------------
23
24 async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {
25 const server = res.locals.server as ServerModel
26
27 server.redundancyAllowed = req.body.redundancyAllowed
28
29 await server.save()
30
31 return res.sendStatus(204)
32 }