✨ add option to disable all rate limits
This commit is contained in:
		
							parent
							
								
									8d611abe45
								
							
						
					
					
						commit
						cc33e87a14
					
				| @ -6,6 +6,8 @@ export function BodyParser(opts?: OptionsJson) { | |||||||
| 	const jsonParser = bodyParser.json(opts); | 	const jsonParser = bodyParser.json(opts); | ||||||
| 
 | 
 | ||||||
| 	return (req: Request, res: Response, next: NextFunction) => { | 	return (req: Request, res: Response, next: NextFunction) => { | ||||||
|  | 		if (!req.headers["content-type"]) req.headers["content-type"] = "application/json"; | ||||||
|  | 
 | ||||||
| 		jsonParser(req, res, (err) => { | 		jsonParser(req, res, (err) => { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				// TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...)
 | 				// TODO: different errors for body parser (request size limit, wrong body type, invalid body, ...)
 | ||||||
|  | |||||||
| @ -107,7 +107,8 @@ export default function rateLimit(opts: { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function initRateLimits(app: Router) { | 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) => { | 	await listenEvent(EventRateLimit, (event) => { | ||||||
| 		Cache.set(event.channel_id as string, event.data); | 		Cache.set(event.channel_id as string, event.data); | ||||||
| 		event.acknowledge?.(); | 		event.acknowledge?.(); | ||||||
|  | |||||||
| @ -77,6 +77,7 @@ export interface ConfigValue { | |||||||
| 			maxWebhooks: number; | 			maxWebhooks: number; | ||||||
| 		}; | 		}; | ||||||
| 		rate: { | 		rate: { | ||||||
|  | 			disabled: boolean; | ||||||
| 			ip: Omit<RateLimitOptions, "bot_count">; | 			ip: Omit<RateLimitOptions, "bot_count">; | ||||||
| 			global: RateLimitOptions; | 			global: RateLimitOptions; | ||||||
| 			error: RateLimitOptions; | 			error: RateLimitOptions; | ||||||
| @ -188,6 +189,7 @@ export const DefaultConfigOptions: ConfigValue = { | |||||||
| 			maxWebhooks: 10, | 			maxWebhooks: 10, | ||||||
| 		}, | 		}, | ||||||
| 		rate: { | 		rate: { | ||||||
|  | 			disabled: true, | ||||||
| 			ip: { | 			ip: { | ||||||
| 				count: 500, | 				count: 500, | ||||||
| 				window: 5, | 				window: 5, | ||||||
|  | |||||||
| @ -161,15 +161,13 @@ export class User extends BaseClass { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) { | 	static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) { | ||||||
| 		const user = await User.findOne( | 		return await User.findOneOrFail( | ||||||
| 			{ id: user_id }, | 			{ id: user_id }, | ||||||
| 			{ | 			{ | ||||||
| 				...opts, | 				...opts, | ||||||
| 				select: [...PublicUserProjection, ...(opts?.select || [])], | 				select: [...PublicUserProjection, ...(opts?.select || [])], | ||||||
| 			} | 			} | ||||||
| 		); | 		); | ||||||
| 		if (!user) throw new HTTPError("User not found", 404); |  | ||||||
| 		return user; |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ export const Config = { | |||||||
| 	get: function get() { | 	get: function get() { | ||||||
| 		return config.value as ConfigValue; | 		return config.value as ConfigValue; | ||||||
| 	}, | 	}, | ||||||
| 	set: function set(val: any) { | 	set: function set(val: Partial<ConfigValue>) { | ||||||
| 		if (!config) return; | 		if (!config) return; | ||||||
| 		config.value = val.merge(config?.value || {}); | 		config.value = val.merge(config?.value || {}); | ||||||
| 		return config.save(); | 		return config.save(); | ||||||
|  | |||||||
| @ -1,3 +1,4 @@ | |||||||
|  | import path from "path"; | ||||||
| import "reflect-metadata"; | import "reflect-metadata"; | ||||||
| import { Connection, createConnection, ValueTransformer } from "typeorm"; | import { Connection, createConnection, ValueTransformer } from "typeorm"; | ||||||
| import * as Models from "../entities"; | import * as Models from "../entities"; | ||||||
| @ -15,7 +16,7 @@ export function initDatabase() { | |||||||
| 	// @ts-ignore
 | 	// @ts-ignore
 | ||||||
| 	promise = createConnection({ | 	promise = createConnection({ | ||||||
| 		type: "sqlite", | 		type: "sqlite", | ||||||
| 		database: "database.db", | 		database: path.join(process.cwd(), "database.db"), | ||||||
| 		// type: "postgres",
 | 		// type: "postgres",
 | ||||||
| 		// url: "postgres://fosscord:wb94SmuURM2Syv&@localhost/fosscord",
 | 		// url: "postgres://fosscord:wb94SmuURM2Syv&@localhost/fosscord",
 | ||||||
| 		//
 | 		//
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user