randydev commited on
Commit
14b551c
·
verified ·
1 Parent(s): ee76c0c

Update plugins/federations.js

Browse files
Files changed (1) hide show
  1. plugins/federations.js +41 -1
plugins/federations.js CHANGED
@@ -20,7 +20,7 @@ FedsRoutes.post("/api/v1/fed/newfed", authenticateApiKey, apiLimiter, async (req
20
  }
21
  });
22
 
23
- FedsRoutes.post("/api/v1/fed/subfed", async (req, res) => {
24
  try {
25
  const { parent_uuid, child_uuid } = req.body;
26
 
@@ -40,4 +40,44 @@ FedsRoutes.post("/api/v1/fed/subfed", async (req, res) => {
40
  }
41
  });
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  export { FedsRoutes };
 
20
  }
21
  });
22
 
23
+ FedsRoutes.post("/api/v1/fed/subfed", authenticateApiKey, apiLimiter, async (req, res) => {
24
  try {
25
  const { parent_uuid, child_uuid } = req.body;
26
 
 
40
  }
41
  });
42
 
43
+ FedsRoutes.get("/api/v1/fed/getfed/:uuid", authenticateApiKey, apiLimiter, async (req, res) => {
44
+ try {
45
+ const federation = await Federation.findOne({ uuid: req.params.uuid });
46
+
47
+ if (!federation) return res.status(404).json({ error: "Federation not found" });
48
+
49
+ const subFeds = await Federation.find({ uuid: { $in: federation.sub_federations } });
50
+
51
+ res.json({ federation, sub_federations: subFeds });
52
+ } catch (err) {
53
+ res.status(500).json({ error: err.message });
54
+ }
55
+ });
56
+
57
+ FedsRoutes.post("/api/v1/fed/ban", authenticateApiKey, apiLimiter, async (req, res) => {
58
+ try {
59
+ const { federation_uuid, user_id } = req.body;
60
+
61
+ const federation = await Federation.findOne({ uuid: federation_uuid });
62
+ if (!federation) return res.status(404).json({ error: "Federation not found" });
63
+
64
+ if (!federation.banned_users.includes(user_id)) {
65
+ federation.banned_users.push(user_id);
66
+ await federation.save();
67
+ }
68
+
69
+ const subFeds = await Federation.find({ uuid: { $in: federation.sub_federations } });
70
+ for (const subFed of subFeds) {
71
+ if (!subFed.banned_users.includes(user_id)) {
72
+ subFed.banned_users.push(user_id);
73
+ await subFed.save();
74
+ }
75
+ }
76
+
77
+ res.json({ message: `User ${user_id} banned in ${federation.name} and all its sub-federations` });
78
+ } catch (err) {
79
+ res.status(500).json({ error: err.message });
80
+ }
81
+ });
82
+
83
  export { FedsRoutes };