refactor: move ratelimits to a generic system for all web servers

This commit is contained in:
Zomatree
2025-09-16 19:15:34 +01:00
committed by Angelo Kontaxis
parent 3a3415915f
commit fb4011084d
16 changed files with 705 additions and 358 deletions

View File

@@ -0,0 +1,28 @@
use axum::http::{request::Parts, Method};
use revolt_ratelimits::ratelimiter::RatelimitResolver;
pub struct AutumnRatelimits;
impl RatelimitResolver<Parts> for AutumnRatelimits {
fn resolve_bucket<'a>(&self, parts: &'a Parts) -> (&'a str, Option<&'a str>) {
let path = parts
.uri
.path()
.trim_matches('/')
.split_terminator("/")
.collect::<Vec<&str>>();
match (&parts.method, path.as_slice()) {
(&Method::POST, &[tag]) => ("upload", Some(tag)),
_ => ("any", None),
}
}
fn resolve_bucket_limit(&self, bucket: &str) -> u32 {
match bucket {
"upload" => 10,
"any" => u32::MAX,
_ => unreachable!("Bucket defined but no limit set"),
}
}
}