Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Nov 28, 2023
1 parent 349b438 commit 52be4b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/web/api/v1/contexts/torrent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::services::torrent_file::generate_random_torrent;
use crate::utils::parse_torrent;
use crate::web::api::v1::auth::get_optional_logged_in_user;
use crate::web::api::v1::extractors::bearer_token::Extract;
use crate::web::api::v1::extractors::user_id::ExtractLoggedInUser;
use crate::web::api::v1::responses::OkResponseData;
use crate::web::api::v1::routes::API_VERSION_URL_PREFIX;

Expand All @@ -37,14 +38,9 @@ use crate::web::api::v1::routes::API_VERSION_URL_PREFIX;
#[allow(clippy::unused_async)]
pub async fn upload_torrent_handler(
State(app_data): State<Arc<AppData>>,
Extract(maybe_bearer_token): Extract,
ExtractLoggedInUser(logged_in_user): ExtractLoggedInUser,
multipart: Multipart,
) -> Response {
let user_id = match app_data.auth.get_user_id_from_bearer_token(&maybe_bearer_token).await {
Ok(user_id) => user_id,
Err(error) => return error.into_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(),
Expand All @@ -53,7 +49,7 @@ pub async fn upload_torrent_handler(
match app_data.torrent_service.add_torrent(add_torrent_form, user_id).await {
Ok(response) => new_torrent_response(&response).into_response(),
Err(error) => error.into_response(),
}
};
}

#[derive(Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions src/web/api/v1/extractors/user_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::bearer_token;
use crate::services;
use crate::web::api::v1::auth::{self, Authentication};

pub struct ExtractLoggedInUser(pub Option<UserId>);
pub struct ExtractLoggedInUser(pub UserId);

#[derive(Deserialize, Debug)]
pub struct UserId(i64);
Expand Down Expand Up @@ -44,7 +44,7 @@ where
let auth: Authentication = auth::Authentication::new(Arc::new(bearer_token));

match auth.get_user_id_from_bearer_token(&maybe_bearer_token).await {
Ok(user_id) => Ok(ExtractLoggedInUser(Some(UserId(user_id)))),
Ok(user_id) => Ok(ExtractLoggedInUser(UserId(user_id))),
Err(error) => return Err(error.into_response()),
}
}
Expand Down

0 comments on commit 52be4b0

Please sign in to comment.