summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--api/src/middlewares/BodyParser.ts2
-rw-r--r--api/src/middlewares/RateLimit.ts3
-rw-r--r--util/src/entities/Config.ts2
-rw-r--r--util/src/entities/User.ts4
-rw-r--r--util/src/util/Config.ts2
-rw-r--r--util/src/util/Database.ts3
6 files changed, 10 insertions, 6 deletions
diff --git a/api/src/middlewares/BodyParser.ts b/api/src/middlewares/BodyParser.ts
index b0ff699d..4cb376bc 100644
--- a/api/src/middlewares/BodyParser.ts
+++ b/api/src/middlewares/BodyParser.ts
@@ -6,6 +6,8 @@ export function BodyParser(opts?: OptionsJson) {
 	const jsonParser = bodyParser.json(opts);
 
 	return (req: Request, res: Response, next: NextFunction) => {
+		if (!req.headers["content-type"]) req.headers["content-type"] = "application/json";
+
 		jsonParser(req, res, (err) => {
 			if (err) {
 				// TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...)
diff --git a/api/src/middlewares/RateLimit.ts b/api/src/middlewares/RateLimit.ts
index d1fd072f..1a38cfcf 100644
--- a/api/src/middlewares/RateLimit.ts
+++ b/api/src/middlewares/RateLimit.ts
@@ -107,7 +107,8 @@ export default function rateLimit(opts: {
 }
 
 export async function initRateLimits(app: Router) {
-	const { routes, global, ip, error } = Config.get().limits.rate;
+	const { routes, global, ip, error, disabled } = Config.get().limits.rate;
+	if (disabled) return;
 	await listenEvent(EventRateLimit, (event) => {
 		Cache.set(event.channel_id as string, event.data);
 		event.acknowledge?.();
diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts
index f969b6bb..a460b437 100644
--- a/util/src/entities/Config.ts
+++ b/util/src/entities/Config.ts
@@ -77,6 +77,7 @@ export interface ConfigValue {
 			maxWebhooks: number;
 		};
 		rate: {
+			disabled: boolean;
 			ip: Omit<RateLimitOptions, "bot_count">;
 			global: RateLimitOptions;
 			error: RateLimitOptions;
@@ -188,6 +189,7 @@ export const DefaultConfigOptions: ConfigValue = {
 			maxWebhooks: 10,
 		},
 		rate: {
+			disabled: true,
 			ip: {
 				count: 500,
 				window: 5,
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 4c86b2d8..b5c2c308 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -161,15 +161,13 @@ export class User extends BaseClass {
 	}
 
 	static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) {
-		const user = await User.findOne(
+		return await User.findOneOrFail(
 			{ id: user_id },
 			{
 				...opts,
 				select: [...PublicUserProjection, ...(opts?.select || [])],
 			}
 		);
-		if (!user) throw new HTTPError("User not found", 404);
-		return user;
 	}
 }
 
diff --git a/util/src/util/Config.ts b/util/src/util/Config.ts
index 1ec71ad0..c87d598e 100644
--- a/util/src/util/Config.ts
+++ b/util/src/util/Config.ts
@@ -14,7 +14,7 @@ export const Config = {
 	get: function get() {
 		return config.value as ConfigValue;
 	},
-	set: function set(val: any) {
+	set: function set(val: Partial<ConfigValue>) {
 		if (!config) return;
 		config.value = val.merge(config?.value || {});
 		return config.save();
diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts
index c22d8abd..0c3d7cef 100644
--- a/util/src/util/Database.ts
+++ b/util/src/util/Database.ts
@@ -1,3 +1,4 @@
+import path from "path";
 import "reflect-metadata";
 import { Connection, createConnection, ValueTransformer } from "typeorm";
 import * as Models from "../entities";
@@ -15,7 +16,7 @@ export function initDatabase() {
 	// @ts-ignore
 	promise = createConnection({
 		type: "sqlite",
-		database: "database.db",
+		database: path.join(process.cwd(), "database.db"),
 		// type: "postgres",
 		// url: "postgres://fosscord:wb94SmuURM2Syv&@localhost/fosscord",
 		//