summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorErkin Alp Güney <erkinalp9035@gmail.com>2022-08-23 23:11:51 +0300
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-12-19 20:49:38 +1100
commit8eff4de19d0f11dfe450eadce61cf4fc58fd5464 (patch)
tree2016c6eed5bef0e1fd2aaf096f748ab9ae0ba5d6 /src/api
parentfix user profile not displaying correctly (diff)
downloadserver-8eff4de19d0f11dfe450eadce61cf4fc58fd5464.tar.xz
flags related rights and stats api
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/policies/stats.ts22
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;