1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-21 10:11:34 +02:00

🚧 rate limit

This commit is contained in:
Flam3rboy 2021-06-28 18:43:50 +02:00
parent e542df3377
commit 14a31ad143
2 changed files with 30 additions and 8 deletions

View File

@ -38,7 +38,6 @@
"atomically": "^1.7.0",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"canvas": "^2.8.0",
"cheerio": "^1.0.0-rc.9",
"dot-prop": "^6.0.1",
"dotenv": "^8.2.0",
@ -50,13 +49,15 @@
"i18next-http-middleware": "^3.1.3",
"i18next-node-fs-backend": "^2.1.3",
"image-size": "^1.0.0",
"ipdata": "^1.1.3",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.5",
"missing-native-js-functions": "^1.2.6",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",
"multer": "^1.4.2"
"multer": "^1.4.2",
"node-fetch": "^2.6.1"
},
"devDependencies": {
"@types/bcrypt": "^3.0.0",
@ -68,9 +69,7 @@
"@types/node-fetch": "^2.5.7",
"@zerollup/ts-transform-paths": "^1.7.18",
"0x": "^4.10.2",
"ipdata": "^1.1.3",
"jest": "^26.6.3",
"node-fetch": "^2.6.1",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
"typescript": "^4.1.2"

View File

@ -1,8 +1,31 @@
import { db, MongooseCache } from "@fosscord/server-util";
import { NextFunction } from "express";
import { NextFunction, Request, Response } from "express";
const Cache = new MongooseCache(db.collection("ratelimit"), [], { onlyEvents: false });
const Cache = new MongooseCache(db.collection("ratelimits"), [{ $match: { blocked: true } }], { onlyEvents: false, array: true });
export default function RateLimit({}) {
return async (req: Request, res: Response, next: NextFunction) => {};
// Docs: https://discord.com/developers/docs/topics/rate-limits
/*
? bucket limit? Max actions/sec per bucket?
TODO: ip rate limit
TODO: user rate limit
TODO: different rate limit for bots/user/oauth/webhook
TODO: delay database requests to include multiple queries
TODO: different for methods (GET/POST)
TODO: bucket major parameters (channel_id, guild_id, webhook_id)
TODO: use config values
> IP addresses that make too many invalid HTTP requests are automatically and temporarily restricted from accessing the Discord API. Currently, this limit is 10,000 per 10 minutes. An invalid request is one that results in 401, 403, or 429 statuses.
> All bots can make up to 50 requests per second to our API. This is independent of any individual rate limit on a route. If your bot gets big enough, based on its functionality, it may be impossible to stay below 50 requests per second during normal operations.
*/
export default function RateLimit(opts: { bucket?: string; window: number; count: number }) {
Cache.init(); // will only initalize it once
return async (req: Request, res: Response, next: NextFunction) => {
next();
};
}