Skip to content

Commit

Permalink
Merge #258: Increase max request body size to 10MB
Browse files Browse the repository at this point in the history
a8aad7a fix: clippy errors (Jose Celano)
35a5430 feat: increase max request body size to 10MB (Jose Celano)

Pull request description:

  Torrent files containing a lot of files (for example datasets) are big. In the future, this should be a config option.

Top commit has no ACKs.

Tree-SHA512: 8f27439bc8bf51975f340d705159d6afcff3ff2fdec4c2a9666cbbef8cd2903be2652cfb67bbbe4e9b7e6db9a6f6856509427e373369605a71c1720cb8768e0e
  • Loading branch information
josecelano committed Aug 21, 2023
2 parents 4d6ab95 + a8aad7a commit 022e2c5
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl Database for Mysql {
let announce_urls = announce_urls.iter().flatten().collect::<Vec<&String>>();

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)
Expand Down
2 changes: 1 addition & 1 deletion src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ impl Database for Sqlite {
let announce_urls = announce_urls.iter().flatten().collect::<Vec<&String>>();

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)
Expand Down
2 changes: 1 addition & 1 deletion src/services/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions src/services/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/web/api/v1/contexts/category/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
4 changes: 2 additions & 2 deletions src/web/api/v1/contexts/tag/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand All @@ -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(),
}
}
2 changes: 1 addition & 1 deletion src/web/api/v1/contexts/user/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
7 changes: 5 additions & 2 deletions src/web/api/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,9 +36,11 @@ pub fn router(app_data: Arc<AppData>) -> 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))
}

0 comments on commit 022e2c5

Please sign in to comment.