diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/routes/policies/stats.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/api/routes/policies/stats.ts b/src/api/routes/policies/stats.ts new file mode 100644 index 00000000..5ef4c3c6 --- /dev/null +++ b/src/api/routes/policies/stats.ts @@ -0,0 +1,22 @@ +import { route } from "@fosscord/api"; +import { Config, getRights, Guild, Member, Message, User } from "@fosscord/util"; +import { Request, Response, Router } from "express"; +const router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + if (!Config.get().security.statsWorldReadable) { + const rights = await getRights(req.user_id); + rights.hasThrow("VIEW_SERVER_STATS"); + } + + res.json({ + counts: { + user: await User.count(), + guild: await Guild.count(), + message: await Message.count(), + members: await Member.count(), + } + }); +}); + +export default router; |