summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/routes/policies/instance/domains.ts41
-rw-r--r--src/api/routes/policies/instance/index.ts20
-rw-r--r--src/api/routes/policies/instance/limits.ts20
-rw-r--r--src/api/routes/policies/stats.ts41
-rw-r--r--src/util/config/types/subconfigurations/limits/RateLimits.ts4
-rw-r--r--src/util/schemas/responses/GeneralConfigurationResponse.ts3
-rw-r--r--src/util/schemas/responses/InstanceDomainsResponse.ts6
-rw-r--r--src/util/schemas/responses/InstanceStatsResponse.ts8
-rw-r--r--src/util/schemas/responses/LimitsConfigurationResponse.ts3
-rw-r--r--src/util/schemas/responses/index.ts4
10 files changed, 110 insertions, 40 deletions
diff --git a/src/api/routes/policies/instance/domains.ts b/src/api/routes/policies/instance/domains.ts
index 696a8510..afeb0e85 100644
--- a/src/api/routes/policies/instance/domains.ts
+++ b/src/api/routes/policies/instance/domains.ts
@@ -16,25 +16,38 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import { Router, Request, Response } from "express";
 import { route } from "@spacebar/api";
 import { Config } from "@spacebar/util";
+import { Request, Response, Router } from "express";
 const router = Router();
 
-router.get("/", route({}), async (req: Request, res: Response) => {
-	const { cdn, gateway, api } = Config.get();
+router.get(
+	"/",
+	route({
+		responses: {
+			200: {
+				body: "InstanceDomainsResponse",
+			},
+		},
+	}),
+	async (req: Request, res: Response) => {
+		const { cdn, gateway, api } = Config.get();
 
-	const IdentityForm = {
-		cdn: cdn.endpointPublic || process.env.CDN || "http://localhost:3001",
-		gateway:
-			gateway.endpointPublic ||
-			process.env.GATEWAY ||
-			"ws://localhost:3001",
-		defaultApiVersion: api.defaultVersion ?? 9,
-		apiEndpoint: api.endpointPublic ?? "http://localhost:3001/api/",
-	};
+		const IdentityForm = {
+			cdn:
+				cdn.endpointPublic ||
+				process.env.CDN ||
+				"http://localhost:3001",
+			gateway:
+				gateway.endpointPublic ||
+				process.env.GATEWAY ||
+				"ws://localhost:3001",
+			defaultApiVersion: api.defaultVersion ?? 9,
+			apiEndpoint: api.endpointPublic ?? "http://localhost:3001/api/",
+		};
 
-	res.json(IdentityForm);
-});
+		res.json(IdentityForm);
+	},
+);
 
 export default router;
diff --git a/src/api/routes/policies/instance/index.ts b/src/api/routes/policies/instance/index.ts
index 68ce3b42..4b4bc194 100644
--- a/src/api/routes/policies/instance/index.ts
+++ b/src/api/routes/policies/instance/index.ts
@@ -16,14 +16,24 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import { Router, Request, Response } from "express";
 import { route } from "@spacebar/api";
 import { Config } from "@spacebar/util";
+import { Request, Response, Router } from "express";
 const router = Router();
 
-router.get("/", route({}), async (req: Request, res: Response) => {
-	const { general } = Config.get();
-	res.json(general);
-});
+router.get(
+	"/",
+	route({
+		responses: {
+			200: {
+				body: "GeneralConfigurationResponse",
+			},
+		},
+	}),
+	async (req: Request, res: Response) => {
+		const { general } = Config.get();
+		res.json(general);
+	},
+);
 
 export default router;
diff --git a/src/api/routes/policies/instance/limits.ts b/src/api/routes/policies/instance/limits.ts
index a6f13170..e144a5bc 100644
--- a/src/api/routes/policies/instance/limits.ts
+++ b/src/api/routes/policies/instance/limits.ts
@@ -16,14 +16,24 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import { Router, Request, Response } from "express";
 import { route } from "@spacebar/api";
 import { Config } from "@spacebar/util";
+import { Request, Response, Router } from "express";
 const router = Router();
 
-router.get("/", route({}), async (req: Request, res: Response) => {
-	const { limits } = Config.get();
-	res.json(limits);
-});
+router.get(
+	"/",
+	route({
+		responses: {
+			200: {
+				body: "LimitsConfigurationResponse",
+			},
+		},
+	}),
+	async (req: Request, res: Response) => {
+		const { limits } = Config.get();
+		res.json(limits);
+	},
+);
 
 export default router;
diff --git a/src/api/routes/policies/stats.ts b/src/api/routes/policies/stats.ts
index 3939e1e8..b2cd3d5a 100644
--- a/src/api/routes/policies/stats.ts
+++ b/src/api/routes/policies/stats.ts
@@ -28,20 +28,33 @@ import {
 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(),
+router.get(
+	"/",
+	route({
+		responses: {
+			200: {
+				body: "InstanceStatsResponse",
+			},
+			403: {
+				body: "APIErrorResponse",
+			},
 		},
-	});
-});
+	}),
+	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;
diff --git a/src/util/config/types/subconfigurations/limits/RateLimits.ts b/src/util/config/types/subconfigurations/limits/RateLimits.ts
index caba740b..0ce0827c 100644
--- a/src/util/config/types/subconfigurations/limits/RateLimits.ts
+++ b/src/util/config/types/subconfigurations/limits/RateLimits.ts
@@ -16,11 +16,11 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import { RouteRateLimit, RateLimitOptions } from ".";
+import { RateLimitOptions, RouteRateLimit } from ".";
 
 export class RateLimits {
 	enabled: boolean = false;
-	ip: Omit<RateLimitOptions, "bot_count"> = {
+	ip: RateLimitOptions = {
 		count: 500,
 		window: 5,
 	};
diff --git a/src/util/schemas/responses/GeneralConfigurationResponse.ts b/src/util/schemas/responses/GeneralConfigurationResponse.ts
new file mode 100644
index 00000000..4feaa32d
--- /dev/null
+++ b/src/util/schemas/responses/GeneralConfigurationResponse.ts
@@ -0,0 +1,3 @@
+import { GeneralConfiguration } from "../../config";
+
+export type GeneralConfigurationResponse = GeneralConfiguration;
diff --git a/src/util/schemas/responses/InstanceDomainsResponse.ts b/src/util/schemas/responses/InstanceDomainsResponse.ts
new file mode 100644
index 00000000..60367492
--- /dev/null
+++ b/src/util/schemas/responses/InstanceDomainsResponse.ts
@@ -0,0 +1,6 @@
+export interface InstanceDomainsResponse {
+	cdn: string;
+	gateway: string;
+	defaultApiVersion: string;
+	apiEndpoint: string;
+}
diff --git a/src/util/schemas/responses/InstanceStatsResponse.ts b/src/util/schemas/responses/InstanceStatsResponse.ts
new file mode 100644
index 00000000..d24fd434
--- /dev/null
+++ b/src/util/schemas/responses/InstanceStatsResponse.ts
@@ -0,0 +1,8 @@
+export interface InstanceStatsResponse {
+	counts: {
+		user: number;
+		guild: number;
+		message: number;
+		members: number;
+	};
+}
diff --git a/src/util/schemas/responses/LimitsConfigurationResponse.ts b/src/util/schemas/responses/LimitsConfigurationResponse.ts
new file mode 100644
index 00000000..f40ab918
--- /dev/null
+++ b/src/util/schemas/responses/LimitsConfigurationResponse.ts
@@ -0,0 +1,3 @@
+import { LimitsConfiguration } from "../../config";
+
+export type LimitsConfigurationResponse = LimitsConfiguration;
diff --git a/src/util/schemas/responses/index.ts b/src/util/schemas/responses/index.ts
index c5e18406..1e4f30cb 100644
--- a/src/util/schemas/responses/index.ts
+++ b/src/util/schemas/responses/index.ts
@@ -11,6 +11,7 @@ export * from "./ChannelPinsResponse";
 export * from "./ChannelWebhooksResponse";
 export * from "./GatewayBotResponse";
 export * from "./GatewayResponse";
+export * from "./GeneralConfigurationResponse";
 export * from "./GenerateRegistrationTokensResponse";
 export * from "./GuildBansResponse";
 export * from "./GuildChannelsResponse";
@@ -29,6 +30,9 @@ export * from "./GuildVanityUrl";
 export * from "./GuildVoiceRegionsResponse";
 export * from "./GuildWidgetJsonResponse";
 export * from "./GuildWidgetSettingsResponse";
+export * from "./InstanceDomainsResponse";
+export * from "./InstanceStatsResponse";
+export * from "./LimitsConfigurationResponse";
 export * from "./LocationMetadataResponse";
 export * from "./MemberJoinGuildResponse";
 export * from "./OAuthAuthorizeResponse";