add: check ip ban endpoint

This commit is contained in:
trisua 2025-07-23 14:44:47 -04:00
parent 8786cb4781
commit e78c43ab62
8 changed files with 68 additions and 6 deletions

View file

@ -1,12 +1,34 @@
use crate::{
State, get_user_from_token,
get_app_from_key, get_user_from_token,
model::{ApiReturn, Error},
routes::api::v1::CreateIpBan,
State,
};
use axum::{Extension, Json, extract::Path, response::IntoResponse};
use axum::{extract::Path, http::HeaderMap, response::IntoResponse, Extension, Json};
use crate::cookie::CookieJar;
use tetratto_core::model::{addr::RemoteAddr, auth::IpBan, permissions::FinePermission};
/// Check if the given IP is banned.
pub async fn check_request(
headers: HeaderMap,
Path(ip): Path<String>,
Extension(data): Extension<State>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
if get_app_from_key!(data, headers).is_none() {
return Json(Error::NotAllowed.into());
}
Json(ApiReturn {
ok: true,
message: "Success".to_string(),
payload: data
.get_ipban_by_addr(&RemoteAddr::from(ip.as_str()))
.await
.is_ok(),
})
}
/// Create a new IP ban.
pub async fn create_request(
jar: CookieJar,