]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/server/redundancy.ts
Optimize SQL requests of watch page API endpoints
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / redundancy.ts
CommitLineData
c48e82b5
C
1import * as express from 'express'
2import { UserRight } from '../../../../shared/models/users'
3import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
4import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy'
5import { ServerModel } from '../../../models/server/server'
6
7const serverRedundancyRouter = express.Router()
8
9serverRedundancyRouter.put('/redundancy/:host',
10 authenticate,
11 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
12 asyncMiddleware(updateServerRedundancyValidator),
13 asyncMiddleware(updateRedundancy)
14)
15
16// ---------------------------------------------------------------------------
17
18export {
19 serverRedundancyRouter
20}
21
22// ---------------------------------------------------------------------------
23
24async 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}