Skip to content

Commit a59db9b

Browse files
committed
feat: [#256] add original infohash to upload torrent response
```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.
1 parent 140895a commit a59db9b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/web/api/v1/contexts/torrent/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub async fn upload_torrent_handler(
4949
};
5050

5151
match app_data.torrent_service.add_torrent(add_torrent_form, user_id).await {
52-
Ok(response) => new_torrent_response(response.torrent_id, &response.info_hash).into_response(),
52+
Ok(response) => new_torrent_response(&response).into_response(),
5353
Err(error) => error.into_response(),
5454
}
5555
}

src/web/api/v1/contexts/torrent/responses.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ use hyper::{header, HeaderMap, StatusCode};
44
use serde::{Deserialize, Serialize};
55

66
use crate::models::torrent::TorrentId;
7+
use crate::services::torrent::AddTorrentResponse;
78
use crate::web::api::v1::responses::OkResponseData;
89

910
#[allow(clippy::module_name_repetitions)]
1011
#[derive(Serialize, Deserialize, Debug)]
1112
pub struct NewTorrentResponseData {
1213
pub torrent_id: TorrentId,
1314
pub info_hash: String,
15+
pub original_info_hash: String,
1416
}
1517

1618
/// Response after successfully uploading a new torrent.
17-
pub fn new_torrent_response(torrent_id: TorrentId, info_hash: &str) -> Json<OkResponseData<NewTorrentResponseData>> {
19+
pub fn new_torrent_response(add_torrent_response: &AddTorrentResponse) -> Json<OkResponseData<NewTorrentResponseData>> {
1820
Json(OkResponseData {
1921
data: NewTorrentResponseData {
20-
torrent_id,
21-
info_hash: info_hash.to_owned(),
22+
torrent_id: add_torrent_response.torrent_id,
23+
info_hash: add_torrent_response.info_hash.clone(),
24+
original_info_hash: add_torrent_response.original_info_hash.clone(),
2225
},
2326
})
2427
}

0 commit comments

Comments
 (0)