randydev commited on
Commit
19eeb57
·
verified ·
1 Parent(s): dbd5f73

Update plugins/federations.js

Browse files
Files changed (1) hide show
  1. plugins/federations.js +71 -0
plugins/federations.js CHANGED
@@ -494,4 +494,75 @@ FedsRoutes.get("/api/v2/federation/fedstats", authenticateApiKey, async (req, re
494
  }
495
  });
496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  export { FedsRoutes };
 
494
  }
495
  });
496
 
497
+ /**
498
+ * @swagger
499
+ * /api/v2/federation/unsubfed:
500
+ * post:
501
+ * summary: Unsubscribe a Sub-Federation
502
+ * tags: [Federation]
503
+ * description: Remove a sub-federation from a parent federation.
504
+ * security:
505
+ * - apiKeyAuth: []
506
+ * requestBody:
507
+ * required: true
508
+ * content:
509
+ * application/json:
510
+ * schema:
511
+ * type: object
512
+ * properties:
513
+ * parent_uuid:
514
+ * type: string
515
+ * description: UUID of the parent federation.
516
+ * child_uuid:
517
+ * type: string
518
+ * description: UUID of the sub-federation to be removed.
519
+ * parameters:
520
+ * - in: header
521
+ * name: x-api-key
522
+ * required: true
523
+ * description: API key for authentication.
524
+ * schema:
525
+ * type: string
526
+ * responses:
527
+ * 200:
528
+ * description: Sub-federation successfully removed.
529
+ * content:
530
+ * application/json:
531
+ * schema:
532
+ * type: object
533
+ * properties:
534
+ * message:
535
+ * type: string
536
+ * example: "Federation SubFed has been unsubscribed from ParentFed."
537
+ * 400:
538
+ * description: Missing or invalid federation UUIDs.
539
+ * 404:
540
+ * description: Federation not found.
541
+ * 500:
542
+ * description: Internal server error.
543
+ */
544
+ FedsRoutes.post("/api/v2/federation/unsubfed", authenticateApiKey, apiLimiter, async (req, res) => {
545
+ try {
546
+ const { parent_uuid, child_uuid } = req.body;
547
+
548
+ if (!parent_uuid || !child_uuid) {
549
+ return res.status(400).json({ error: "Both parent and child federation UUIDs are required." });
550
+ }
551
+
552
+ const parent = await Federation.findOne({ uuid: parent_uuid });
553
+ const child = await Federation.findOne({ uuid: child_uuid });
554
+
555
+ if (!parent || !child) {
556
+ return res.status(404).json({ error: "Federation not found." });
557
+ }
558
+
559
+ parent.sub_federations = parent.sub_federations.filter(uuid => uuid !== child_uuid);
560
+ await parent.save();
561
+
562
+ res.json({ message: `Federation ${child.name} has been unsubscribed from ${parent.name}` });
563
+ } catch (error) {
564
+ res.status(500).json({ error: `Failed to unsubscribe sub-federation: ${error.message}` });
565
+ }
566
+ });
567
+
568
  export { FedsRoutes };