From 836c94d129b5c411e35bad3bd54732c8a55fc6cb Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 3 Aug 2024 16:26:34 +0200 Subject: [PATCH] refactor: [#615] upload torrent handler now uses an optional user id --- src/services/torrent.rs | 6 +++--- src/web/api/server/v1/contexts/torrent/handlers.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/torrent.rs b/src/services/torrent.rs index 0e230246..4715502f 100644 --- a/src/services/torrent.rs +++ b/src/services/torrent.rs @@ -132,10 +132,10 @@ impl Index { pub async fn add_torrent( &self, add_torrent_req: AddTorrentRequest, - user_id: UserId, + maybe_user_id: Option, ) -> Result { self.authorization_service - .authorize(ACTION::AddTorrent, Some(user_id)) + .authorize(ACTION::AddTorrent, maybe_user_id) .await?; let metadata = self.validate_and_build_metadata(&add_torrent_req).await?; @@ -149,7 +149,7 @@ impl Index { let torrent_id = self .torrent_repository - .add(&original_info_hash, &torrent, &metadata, user_id) + .add(&original_info_hash, &torrent, &metadata, maybe_user_id.unwrap()) .await?; // Synchronous secondary tasks diff --git a/src/web/api/server/v1/contexts/torrent/handlers.rs b/src/web/api/server/v1/contexts/torrent/handlers.rs index ffdc6240..9534cc5c 100644 --- a/src/web/api/server/v1/contexts/torrent/handlers.rs +++ b/src/web/api/server/v1/contexts/torrent/handlers.rs @@ -37,7 +37,7 @@ use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX; #[allow(clippy::unused_async)] pub async fn upload_torrent_handler( State(app_data): State>, - ExtractLoggedInUser(user_id): ExtractLoggedInUser, + ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser, multipart: Multipart, ) -> Response { let add_torrent_form = match build_add_torrent_request_from_payload(multipart).await { @@ -45,7 +45,7 @@ pub async fn upload_torrent_handler( Err(error) => return error.into_response(), }; - match app_data.torrent_service.add_torrent(add_torrent_form, user_id).await { + match app_data.torrent_service.add_torrent(add_torrent_form, maybe_user_id).await { Ok(response) => new_torrent_response(&response).into_response(), Err(error) => error.into_response(), }