]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/server/redundancy.ts
Add hook filters tests
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / redundancy.ts
index 4216b9e353835c57c46641c2ec757bd01b87f488..f8109070d5c7a58a9bcf7e0fa7e8c17a9dd766af 100644 (file)
@@ -2,7 +2,8 @@ import * as express from 'express'
 import { UserRight } from '../../../../shared/models/users'
 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
 import { updateServerRedundancyValidator } from '../../../middlewares/validators/redundancy'
-import { ServerModel } from '../../../models/server/server'
+import { removeRedundancyOf } from '../../../lib/redundancy'
+import { logger } from '../../../helpers/logger'
 
 const serverRedundancyRouter = express.Router()
 
@@ -21,12 +22,16 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function updateRedundancy (req: express.Request, res: express.Response, next: express.NextFunction) {
-  const server = res.locals.server as ServerModel
+async function updateRedundancy (req: express.Request, res: express.Response) {
+  const server = res.locals.server
 
   server.redundancyAllowed = req.body.redundancyAllowed
 
   await server.save()
 
+  // Async, could be long
+  removeRedundancyOf(server.id)
+    .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, err))
+
   return res.sendStatus(204)
 }