mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 04:32:35 +01:00
Message rate limiting
This commit is contained in:
parent
9e36eff11d
commit
47b999efec
@ -14,5 +14,36 @@
|
|||||||
"EMAIL_TYPE_INVALID_EMAIL": "Not a well-formed email address",
|
"EMAIL_TYPE_INVALID_EMAIL": "Not a well-formed email address",
|
||||||
"DATE_TYPE_PARSE": "Could not parse {{date}}. Should be ISO8601",
|
"DATE_TYPE_PARSE": "Could not parse {{date}}. Should be ISO8601",
|
||||||
"BASE_TYPE_BAD_LENGTH": "Must be between {{length}} in length"
|
"BASE_TYPE_BAD_LENGTH": "Must be between {{length}} in length"
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"INVALID_BODY": "Invalid Body",
|
||||||
|
"INVALID_REQUEST_SIGNATURE": "Invalid request signature",
|
||||||
|
"MISSING_FILE": "File missing",
|
||||||
|
"INVALID_FILE_TYPE": "Invalid file type"
|
||||||
|
},
|
||||||
|
"notfound": {
|
||||||
|
"CHANNEL": "This channel doesn't exist",
|
||||||
|
"USER": "User not found",
|
||||||
|
"ROLE": "Role not found",
|
||||||
|
"REACTION": "Reaction not found",
|
||||||
|
"FILE": "File not found"
|
||||||
|
},
|
||||||
|
"toomany": {
|
||||||
|
"CHANNEL": "Too many channels",
|
||||||
|
"USER": "Too many users",
|
||||||
|
"ROLE": "Too many roles",
|
||||||
|
"REACTION": "Too many reactions",
|
||||||
|
"FILE": "Too many files",
|
||||||
|
"MESSAGE": "Too many messages"
|
||||||
|
},
|
||||||
|
"relationship": {
|
||||||
|
"ALREADY_BLOCKED": "You already blocked the user",
|
||||||
|
"NOT_FRIENDS": "You are not friends with the user",
|
||||||
|
"ALREADY_FRIENDS": "You are already friends with the user",
|
||||||
|
"ALREADY_SENT": "You already sent a friend request",
|
||||||
|
"ADD_SELF": "You can't add yourself as a friend",
|
||||||
|
"REMOVE_SELF": "You can't remove yourself as a friend",
|
||||||
|
"UNBLOCK": "Unblock the user before sending a friend request",
|
||||||
|
"BLOCKED": "The user blocked you"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
Config,
|
Config,
|
||||||
DmChannelDTO,
|
DmChannelDTO,
|
||||||
emitEvent,
|
emitEvent,
|
||||||
|
FieldErrors,
|
||||||
getPermission,
|
getPermission,
|
||||||
Message,
|
Message,
|
||||||
MessageCreateEvent,
|
MessageCreateEvent,
|
||||||
@ -16,10 +17,13 @@ import {
|
|||||||
MessageCreateSchema,
|
MessageCreateSchema,
|
||||||
ReadState,
|
ReadState,
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
|
getRights,
|
||||||
|
Rights,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
import { handleMessage, postHandleMessage, route, getIpAdress } from "@fosscord/api";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
|
import { yellow } from "picocolors";
|
||||||
import { FindManyOptions, LessThan, MoreThan } from "typeorm";
|
import { FindManyOptions, LessThan, MoreThan } from "typeorm";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
|
|
||||||
@ -215,6 +219,23 @@ router.post(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!req.rights.has(Rights.FLAGS.BYPASS_RATE_LIMITS)) {
|
||||||
|
var limits = Config.get().limits;
|
||||||
|
if (limits.absoluteRate.register.enabled) {
|
||||||
|
const count = await Message.count({
|
||||||
|
where: {
|
||||||
|
channel_id,
|
||||||
|
timestamp: MoreThan(new Date(Date.now() - limits.absoluteRate.sendMessage.window))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (count >= limits.absoluteRate.sendMessage.limit)
|
||||||
|
throw FieldErrors({
|
||||||
|
channel_id: { code: "TOO_MANY_MESSAGES", message: req.t("common:toomany.MESSAGE") }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const files = (req.files as Express.Multer.File[]) ?? [];
|
const files = (req.files as Express.Multer.File[]) ?? [];
|
||||||
for (var currFile of files) {
|
for (var currFile of files) {
|
||||||
try {
|
try {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export class GlobalRateLimits {
|
export class GlobalRateLimits {
|
||||||
register: GlobalRateLimit = { limit: 25, window: 60 * 60 * 1000, enabled: true };
|
register: GlobalRateLimit = { limit: 25, window: 60 * 60 * 1000, enabled: true };
|
||||||
sendMessage: GlobalRateLimit = { limit: 50, window: 60 * 1000, enabled: true };
|
sendMessage: GlobalRateLimit = { limit: 200, window: 60 * 1000, enabled: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GlobalRateLimit {
|
export class GlobalRateLimit {
|
||||||
|
Loading…
Reference in New Issue
Block a user