From 83533919f3c3ff40f49d970e0ac696803ab1bcfa Mon Sep 17 00:00:00 2001 From: shiroyashik Date: Sat, 8 Jun 2024 22:26:44 +0300 Subject: [PATCH] Pre-patch 0.2.1 limitations fixed - Added DefaultBodyLimit control --- docker-compose.example.yml | 6 ++++++ src/auth.rs | 2 +- src/info.rs | 6 ------ src/main.rs | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docker-compose.example.yml b/docker-compose.example.yml index eef4778..9025583 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -5,6 +5,12 @@ services: # build: . image: ghcr.io/shiroyashik/sculptor:latest container_name: sculptor + healthcheck: + test: wget --no-verbose --tries=1 --spider http://sculptor:6665/health || exit 1 + interval: 5s + timeout: 3s + retries: 3 + start_period: 5s restart: unless-stopped volumes: - ./Config.toml:/app/Config.toml:ro diff --git a/src/auth.rs b/src/auth.rs index f0ccecd..f4a84f1 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -52,7 +52,7 @@ async fn verify( State(state): State, ) -> String { let server_id = query.id.clone(); - let username = state.pending.remove(&server_id).unwrap().1; + let username = state.pending.remove(&server_id).unwrap().1; // TODO: Add if let Some((uuid, auth_system)) = has_joined(&server_id, &username).await.unwrap() { info!("[Authorization] {username} logged in using {auth_system:?}"); let authenticated = state.authenticated; diff --git a/src/info.rs b/src/info.rs index d76bfdb..a41683b 100644 --- a/src/info.rs +++ b/src/info.rs @@ -3,12 +3,6 @@ use serde_json::{json, Value}; use crate::AppState; -/// Assert health of the server -/// If times out, the server is considered dead, so we can return basically anything -pub async fn health_check() -> String { - "ok".to_string() -} - pub async fn version() -> Json { Json(json!({ "release": "0.1.4", diff --git a/src/main.rs b/src/main.rs index 61cf871..5b0a9a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ use anyhow::Result; use axum::{ - middleware::from_extractor, - routing::{delete, get, post, put}, - Router, + extract::DefaultBodyLimit, middleware::from_extractor, routing::{delete, get, post, put}, Router }; use dashmap::DashMap; use std::sync::Arc; @@ -94,7 +92,8 @@ pub struct AppState { config: Arc>, } -const LOGGER_ENV: &str = "RUST_LOG"; +const LOGGER_ENV: &'static str = "RUST_LOG"; +const SCULPTOR_VERSION: &'static str = env!("CARGO_PKG_VERSION"); #[tokio::main] async fn main() -> Result<()> { @@ -110,7 +109,7 @@ async fn main() -> Result<()> { let config_file = std::env::var("CONFIG_PATH").unwrap_or_else(|_| "Config.toml".into()); - info!("The Sculptor v{}", env!("CARGO_PKG_VERSION")); + info!("The Sculptor v{}", SCULPTOR_VERSION); // Config let config = Arc::new(Mutex::new(config::Config::parse(config_file.clone().into()))); let listen = config.lock().await.listen.clone(); @@ -139,6 +138,7 @@ async fn main() -> Result<()> { } }); + let max_body_size = state.config.clone().lock().await.limitations.max_avatar_size as usize; let api = Router::new() .nest("//auth", api_auth::router()) .route("/limits", get(api_info::limits)) @@ -146,15 +146,15 @@ async fn main() -> Result<()> { .route("/motd", get(api_info::motd)) .route("/equip", post(api_profile::equip_avatar)) .route("/:uuid", get(api_profile::user_info)) - .route("/:uuid/avatar", get(api_profile::download_avatar)) - .route("/avatar", put(api_profile::upload_avatar)) + .route("/:uuid/avatar", get(api_profile::download_avatar).layer(DefaultBodyLimit::max(max_body_size))) + .route("/avatar", put(api_profile::upload_avatar).layer(DefaultBodyLimit::max(max_body_size))) .route("/avatar", delete(api_profile::delete_avatar)); let app = Router::new() .nest("/api", api) .route("/api/", get(api_auth::status)) .route("/ws", get(handler)) - .route("/health", get(api_info::health_check)) + .route("/health", get(|| async { "ok" })) .route_layer(from_extractor::()) .with_state(state) .layer(TraceLayer::new_for_http().on_request(()));