Skip to content

Commit

Permalink
feat: [#256] add original infohash to upload torrent response
Browse files Browse the repository at this point in the history
```json
{
    "data": {
        "torrent_id": 174,
        "info_hash": "8aa01a4c816332045ffec83247ccbc654547fedf",
        "original_info_hash": "6c690018c5786dbbb00161f62b0712d69296df97"
    }
}
```

`original_info_hash` contains the infohash of the original uploaded
torrent file. It migth change if the torrent contained custom fields in
the info dictionary.
  • Loading branch information
josecelano committed Aug 25, 2023
1 parent 7c047e2 commit 9bb8578
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/web/api/v1/contexts/torrent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,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.torrent_id, &response.info_hash).into_response(),
Ok(response) => new_torrent_response(&response).into_response(),
Err(error) => error.into_response(),
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/web/api/v1/contexts/torrent/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ use hyper::{header, HeaderMap, StatusCode};
use serde::{Deserialize, Serialize};

use crate::models::torrent::TorrentId;
use crate::services::torrent::AddTorrentResponse;
use crate::web::api::v1::responses::OkResponseData;

#[allow(clippy::module_name_repetitions)]
#[derive(Serialize, Deserialize, Debug)]
pub struct NewTorrentResponseData {
pub torrent_id: TorrentId,
pub info_hash: String,
pub original_info_hash: String,
}

/// Response after successfully uploading a new torrent.
pub fn new_torrent_response(torrent_id: TorrentId, info_hash: &str) -> Json<OkResponseData<NewTorrentResponseData>> {
pub fn new_torrent_response(add_torrent_response: &AddTorrentResponse) -> Json<OkResponseData<NewTorrentResponseData>> {
Json(OkResponseData {
data: NewTorrentResponseData {
torrent_id,
info_hash: info_hash.to_owned(),
torrent_id: add_torrent_response.torrent_id,
info_hash: add_torrent_response.info_hash.clone(),
original_info_hash: add_torrent_response.original_info_hash.clone(),
},
})
}
Expand Down

0 comments on commit 9bb8578

Please sign in to comment.