Skip to content

Commit

Permalink
refactor: [#615] redirect to details url with infohash method now cal…
Browse files Browse the repository at this point in the history
…ls the torrent service that implements the authorization layer
  • Loading branch information
mario-nt committed Aug 3, 2024
1 parent f8e7570 commit 543d804
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/web/api/server/v1/contexts/torrent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ pub async fn get_torrent_info_handler(
return errors::Request::InvalidInfoHashParam.into_response();
};

if let Some(redirect_response) = redirect_to_details_url_using_canonical_info_hash_if_needed(&app_data, &info_hash).await {
if let Some(redirect_response) =
redirect_to_details_url_using_canonical_info_hash_if_needed(&app_data, &info_hash, opt_user_id).await
{
redirect_response
} else {
match app_data.torrent_service.get_torrent_info(&info_hash, opt_user_id).await {
Expand All @@ -177,12 +179,9 @@ pub async fn get_torrent_info_handler(
async fn redirect_to_details_url_using_canonical_info_hash_if_needed(
app_data: &Arc<AppData>,
info_hash: &InfoHash,
opt_user_id: Option<i64>,
) -> Option<Response> {
match app_data
.torrent_info_hash_repository
.find_canonical_info_hash_for(info_hash)
.await
{
match app_data.torrent_service.get_canonical_info_hash(info_hash, opt_user_id).await {
Ok(Some(canonical_info_hash)) => {
if canonical_info_hash != *info_hash {
return Some(
Expand Down

0 comments on commit 543d804

Please sign in to comment.