Update plugins/federations.js
Browse files- plugins/federations.js +80 -0
plugins/federations.js
CHANGED
@@ -414,4 +414,84 @@ FedsRoutes.post("/api/v2/federation/ban-check", authenticateApiKey, async (req,
|
|
414 |
}
|
415 |
});
|
416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
export { FedsRoutes };
|
|
|
414 |
}
|
415 |
});
|
416 |
|
417 |
+
/**
|
418 |
+
* @swagger
|
419 |
+
* /api/v2/federation/fedstats:
|
420 |
+
* get:
|
421 |
+
* summary: Get Federation Statistics
|
422 |
+
* tags: [Federation]
|
423 |
+
* description: Retrieve the statistics of a federation, including total banned users and sub-federations.
|
424 |
+
* parameters:
|
425 |
+
* - in: query
|
426 |
+
* name: uuid
|
427 |
+
* required: true
|
428 |
+
* description: UUID of the federation to check stats for.
|
429 |
+
* schema:
|
430 |
+
* type: string
|
431 |
+
* - in: header
|
432 |
+
* name: x-api-key
|
433 |
+
* required: true
|
434 |
+
* description: API key for authentication.
|
435 |
+
* schema:
|
436 |
+
* type: string
|
437 |
+
* responses:
|
438 |
+
* 200:
|
439 |
+
* description: Federation statistics retrieved successfully.
|
440 |
+
* content:
|
441 |
+
* application/json:
|
442 |
+
* schema:
|
443 |
+
* type: object
|
444 |
+
* properties:
|
445 |
+
* success:
|
446 |
+
* type: boolean
|
447 |
+
* example: true
|
448 |
+
* stats:
|
449 |
+
* type: object
|
450 |
+
* properties:
|
451 |
+
* federation_name:
|
452 |
+
* type: string
|
453 |
+
* example: "Example Federation"
|
454 |
+
* total_banned_users:
|
455 |
+
* type: integer
|
456 |
+
* example: 10
|
457 |
+
* total_sub_federations:
|
458 |
+
* type: integer
|
459 |
+
* example: 3
|
460 |
+
* owner:
|
461 |
+
* type: number
|
462 |
+
* example: 123456789
|
463 |
+
* 400:
|
464 |
+
* description: Missing or invalid federation UUID.
|
465 |
+
* 404:
|
466 |
+
* description: Federation not found.
|
467 |
+
* 500:
|
468 |
+
* description: Internal server error.
|
469 |
+
*/
|
470 |
+
FedsRoutes.get("/api/v2/federation/fedstats", authenticateApiKey, async (req, res) => {
|
471 |
+
try {
|
472 |
+
const { uuid } = req.query;
|
473 |
+
|
474 |
+
if (!uuid) {
|
475 |
+
return res.status(400).json({ error: "Federation UUID is required" });
|
476 |
+
}
|
477 |
+
|
478 |
+
const federation = await Federation.findOne({ uuid });
|
479 |
+
|
480 |
+
if (!federation) {
|
481 |
+
return res.status(404).json({ error: "Federation not found" });
|
482 |
+
}
|
483 |
+
|
484 |
+
const stats = {
|
485 |
+
federation_name: federation.name,
|
486 |
+
total_banned_users: federation.banned_users.length,
|
487 |
+
total_sub_federations: federation.sub_federations.length,
|
488 |
+
owner: federation.owner,
|
489 |
+
};
|
490 |
+
|
491 |
+
res.json({ success: true, stats });
|
492 |
+
} catch (error) {
|
493 |
+
res.status(500).json({ error: `Failed to fetch federation stats: ${error.message}` });
|
494 |
+
}
|
495 |
+
});
|
496 |
+
|
497 |
export { FedsRoutes };
|