]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/server/redundancy.ts
Refresh remote actors on GET enpoints
[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'
161b061d
C
6import { removeRedundancyOf } from '../../../lib/redundancy'
7import { logger } from '../../../helpers/logger'
c48e82b5
C
8
9const serverRedundancyRouter = express.Router()
10
11serverRedundancyRouter.put('/redundancy/:host',
12 authenticate,
13 ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
14 asyncMiddleware(updateServerRedundancyValidator),
15 asyncMiddleware(updateRedundancy)
16)
17
18// ---------------------------------------------------------------------------
19
20export {
21 serverRedundancyRouter
22}
23
24// ---------------------------------------------------------------------------
25
26async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {
27 const server = res.locals.server as ServerModel
28
29 server.redundancyAllowed = req.body.redundancyAllowed
30
31 await server.save()
32
161b061d
C
33 // Async, could be long
34 removeRedundancyOf(server.id)
35 .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err))
36
c48e82b5
C
37 return res.sendStatus(204)
38}