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