add ratelimits

This commit is contained in:
Zomatree
2021-09-07 15:48:06 +01:00
parent b0d2e99588
commit 2f452b15b1
7 changed files with 190 additions and 112 deletions

View File

@@ -1,7 +1,7 @@
use std::collections::HashSet;
use crate::database::*;
use crate::util::ratelimit::RateLimited;
use crate::util::ratelimit::{Ratelimiter, RatelimitResponse};
use crate::util::result::{Error, Result};
use mongodb::{bson::doc, options::FindOneOptions};
@@ -34,7 +34,7 @@ lazy_static! {
}
#[post("/<target>/messages", data = "<message>")]
pub async fn message_send(_r: RateLimited<'_>, user: User, target: Ref, message: Json<Data>) -> Result<Value> {
pub async fn message_send(_r: Ratelimiter, user: User, target: Ref, message: Json<Data>) -> Result<RatelimitResponse<Value>> {
let message = message.into_inner();
message
.validate()
@@ -147,5 +147,5 @@ pub async fn message_send(_r: RateLimited<'_>, user: User, target: Ref, message:
msg.clone().publish(&target, perm.get_embed_links()).await?;
Ok(json!(msg))
Ok(RatelimitResponse(json!(msg)))
}

View File

@@ -1,14 +1,13 @@
use crate::util::{ratelimit::RateLimitGuard, variables::{
use crate::util::{ratelimit::Ratelimiter, variables::{
APP_URL, AUTUMN_URL, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, JANUARY_URL, USE_AUTUMN,
USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY, VOSO_URL, VOSO_WS_HOST,
}};
use mongodb::bson::doc;
use rocket::{http::Status, serde::json::Value};
use rocket_governor::RocketGovernor;
#[get("/")]
pub async fn root(_limitguard: RocketGovernor<'_, RateLimitGuard>) -> Value {
pub async fn root() -> Value {
json!({
"revolt": crate::version::VERSION,
"features": {
@@ -39,6 +38,6 @@ pub async fn root(_limitguard: RocketGovernor<'_, RateLimitGuard>) -> Value {
}
#[get("/ping")]
pub async fn ping(_limitguard: RocketGovernor<'_, RateLimitGuard>) -> Status {
pub async fn ping(_limitguard: Ratelimiter) -> Status {
Status::Ok
}