Skip to content

Commit

Permalink
refactor: [#615] upload torrent handler now uses an optional user id
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent 935eb53 commit 836c94d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ impl Index {
pub async fn add_torrent(
&self,
add_torrent_req: AddTorrentRequest,
user_id: UserId,
maybe_user_id: Option<UserId>,
) -> Result<AddTorrentResponse, ServiceError> {
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?;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/web/api/server/v1/contexts/torrent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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<Arc<AppData>>,
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 {
Ok(torrent_request) => torrent_request,
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(),
}
Expand Down

0 comments on commit 836c94d

Please sign in to comment.