From 35a5430f2a5203390a67c575d9b7a5bbdd43f8f0 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 21 Aug 2023 13:16:38 +0100 Subject: [PATCH 1/2] feat: increase max request body size to 10MB Torrent files containing a lot of files (for example datasets) are big. In the future, this should be a config option. --- src/web/api/v1/routes.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/web/api/v1/routes.rs b/src/web/api/v1/routes.rs index 996d3a6c..099a1921 100644 --- a/src/web/api/v1/routes.rs +++ b/src/web/api/v1/routes.rs @@ -2,6 +2,7 @@ use std::env; use std::sync::Arc; +use axum::extract::DefaultBodyLimit; use axum::routing::get; use axum::Router; use tower_http::cors::CorsLayer; @@ -35,9 +36,11 @@ pub fn router(app_data: Arc) -> Router { .route("/", get(about_page_handler).with_state(app_data)) .nest(&format!("/{API_VERSION_URL_PREFIX}"), v1_api_routes); - if env::var(ENV_VAR_CORS_PERMISSIVE).is_ok() { + let router = if env::var(ENV_VAR_CORS_PERMISSIVE).is_ok() { router.layer(CorsLayer::permissive()) } else { router - } + }; + + router.layer(DefaultBodyLimit::max(10_485_760)) } From a8aad7a482fb6fd681c14cd3ee06b566ad60d0ff Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 21 Aug 2023 14:29:26 +0100 Subject: [PATCH 2/2] fix: clippy errors --- src/config.rs | 2 +- src/databases/mysql.rs | 2 +- src/databases/sqlite.rs | 2 +- src/services/category.rs | 2 +- src/services/tag.rs | 4 ++-- src/web/api/v1/contexts/category/handlers.rs | 2 +- src/web/api/v1/contexts/tag/handlers.rs | 4 ++-- src/web/api/v1/contexts/user/handlers.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5a9f1713..abf596d3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -318,7 +318,7 @@ impl Configuration { warn!("No config file found. Creating default config file ..."); let config = Configuration::default(); - let _ = config.save_to_file(config_path).await; + let () = config.save_to_file(config_path).await; return Err(ConfigError::Message(format!( "No config file found. Created default config file in {config_path}. Edit the file and start the application." diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index b35fede6..5b9f1ca4 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -510,7 +510,7 @@ impl Database for Mysql { let announce_urls = announce_urls.iter().flatten().collect::>(); for tracker_url in &announce_urls { - let _ = query("INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)") + let () = query("INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)") .bind(torrent_id) .bind(tracker_url) .execute(&mut tx) diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index 98cb836f..5e8d5a7d 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -498,7 +498,7 @@ impl Database for Sqlite { let announce_urls = announce_urls.iter().flatten().collect::>(); for tracker_url in &announce_urls { - let _ = query("INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)") + let () = query("INSERT INTO torrust_torrent_announce_urls (torrent_id, tracker_url) VALUES (?, ?)") .bind(torrent_id) .bind(tracker_url) .execute(&mut tx) diff --git a/src/services/category.rs b/src/services/category.rs index dbce9023..548a2374 100644 --- a/src/services/category.rs +++ b/src/services/category.rs @@ -65,7 +65,7 @@ impl Service { } match self.category_repository.delete(category_name).await { - Ok(_) => Ok(()), + Ok(()) => Ok(()), Err(e) => match e { DatabaseError::CategoryNotFound => Err(ServiceError::CategoryNotFound), _ => Err(ServiceError::DatabaseError), diff --git a/src/services/tag.rs b/src/services/tag.rs index b766a14b..9bac69b4 100644 --- a/src/services/tag.rs +++ b/src/services/tag.rs @@ -39,7 +39,7 @@ impl Service { } match self.tag_repository.add(tag_name).await { - Ok(_) => Ok(()), + Ok(()) => Ok(()), Err(e) => match e { DatabaseError::TagAlreadyExists => Err(ServiceError::TagAlreadyExists), _ => Err(ServiceError::DatabaseError), @@ -65,7 +65,7 @@ impl Service { } match self.tag_repository.delete(tag_id).await { - Ok(_) => Ok(()), + Ok(()) => Ok(()), Err(e) => match e { DatabaseError::TagNotFound => Err(ServiceError::TagNotFound), _ => Err(ServiceError::DatabaseError), diff --git a/src/web/api/v1/contexts/category/handlers.rs b/src/web/api/v1/contexts/category/handlers.rs index bd66f53a..da0c1209 100644 --- a/src/web/api/v1/contexts/category/handlers.rs +++ b/src/web/api/v1/contexts/category/handlers.rs @@ -81,7 +81,7 @@ pub async fn delete_handler( }; match app_data.category_service.delete_category(&category_form.name, &user_id).await { - Ok(_) => deleted_category(&category_form.name).into_response(), + Ok(()) => deleted_category(&category_form.name).into_response(), Err(error) => error.into_response(), } } diff --git a/src/web/api/v1/contexts/tag/handlers.rs b/src/web/api/v1/contexts/tag/handlers.rs index feb0a745..04293bad 100644 --- a/src/web/api/v1/contexts/tag/handlers.rs +++ b/src/web/api/v1/contexts/tag/handlers.rs @@ -52,7 +52,7 @@ pub async fn add_handler( }; match app_data.tag_service.add_tag(&add_tag_form.name, &user_id).await { - Ok(_) => added_tag(&add_tag_form.name).into_response(), + Ok(()) => added_tag(&add_tag_form.name).into_response(), Err(error) => error.into_response(), } } @@ -77,7 +77,7 @@ pub async fn delete_handler( }; match app_data.tag_service.delete_tag(&delete_tag_form.tag_id, &user_id).await { - Ok(_) => deleted_tag(delete_tag_form.tag_id).into_response(), + Ok(()) => deleted_tag(delete_tag_form.tag_id).into_response(), Err(error) => error.into_response(), } } diff --git a/src/web/api/v1/contexts/user/handlers.rs b/src/web/api/v1/contexts/user/handlers.rs index 51fb041f..c6d69224 100644 --- a/src/web/api/v1/contexts/user/handlers.rs +++ b/src/web/api/v1/contexts/user/handlers.rs @@ -145,7 +145,7 @@ pub async fn ban_handler( }; match app_data.ban_service.ban_user(&to_be_banned_username.0, &user_id).await { - Ok(_) => Json(OkResponseData { + Ok(()) => Json(OkResponseData { data: format!("Banned user: {}", to_be_banned_username.0), }) .into_response(),