randydev commited on
Commit
60d1a19
·
verified ·
1 Parent(s): 421ab9b

Update plugins/federations.js

Browse files
Files changed (1) hide show
  1. plugins/federations.js +27 -4
plugins/federations.js CHANGED
@@ -4,7 +4,7 @@ import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
4
  import { Federation } from '../models.js';
5
  const FedsRoutes = express.Router();
6
 
7
- FedsRoutes.post("/api/v1/fed/newfed", authenticateApiKey, apiLimiter, async (req, res) => {
8
  try {
9
  const { name, owner } = req.body;
10
 
@@ -20,7 +20,7 @@ FedsRoutes.post("/api/v1/fed/newfed", authenticateApiKey, apiLimiter, async (req
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,7 +40,7 @@ FedsRoutes.post("/api/v1/fed/subfed", authenticateApiKey, apiLimiter, async (req
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
 
@@ -54,7 +54,30 @@ FedsRoutes.get("/api/v1/fed/getfed/:uuid", authenticateApiKey, apiLimiter, async
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
 
 
4
  import { Federation } from '../models.js';
5
  const FedsRoutes = express.Router();
6
 
7
+ FedsRoutes.post("/api/v2/federation/newfed", authenticateApiKey, apiLimiter, async (req, res) => {
8
  try {
9
  const { name, owner } = req.body;
10
 
 
20
  }
21
  });
22
 
23
+ FedsRoutes.post("/api/v2/federation/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/federation/getfed/:uuid", authenticateApiKey, apiLimiter, async (req, res) => {
44
  try {
45
  const federation = await Federation.findOne({ uuid: req.params.uuid });
46
 
 
54
  }
55
  });
56
 
57
+ FedsRoutes.post('/api/v2/federation/unban', authenticateApiKey, async (req, res) => {
58
+ try {
59
+ const { name, user_id } = req.body;
60
+
61
+ if (!name || !user_id || isNaN(user_id)) {
62
+ return res.status(400).json({ error: "Federation name and valid user ID required" });
63
+ }
64
+
65
+ const federation = await Federation.findOne({ name });
66
+
67
+ if (!federation) {
68
+ return res.status(404).json({ error: "Federation not found." });
69
+ }
70
+
71
+ federation.banned_users = federation.banned_users.filter(id => id !== user_id);
72
+ await federation.save();
73
+
74
+ res.json({ success: true, message: `User ${user_id} unbanned from federation ${name}.` });
75
+ } catch (error) {
76
+ res.status(500).json({ error: `Failed to unban user: ${error.message}` });
77
+ }
78
+ });
79
+
80
+ FedsRoutes.post("/api/v2/federation/ban", authenticateApiKey, apiLimiter, async (req, res) => {
81
  try {
82
  const { federation_uuid, user_id } = req.body;
83