From 9bb85780f6ee3a978ac1a4c6d54bd88ab623f3fc Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 24 Aug 2023 18:23:50 +0100 Subject: [PATCH] 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. --- src/web/api/v1/contexts/torrent/handlers.rs | 2 +- src/web/api/v1/contexts/torrent/responses.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/web/api/v1/contexts/torrent/handlers.rs b/src/web/api/v1/contexts/torrent/handlers.rs index 1c902522..2165256c 100644 --- a/src/web/api/v1/contexts/torrent/handlers.rs +++ b/src/web/api/v1/contexts/torrent/handlers.rs @@ -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(), } } diff --git a/src/web/api/v1/contexts/torrent/responses.rs b/src/web/api/v1/contexts/torrent/responses.rs index 33ec2a19..9873b420 100644 --- a/src/web/api/v1/contexts/torrent/responses.rs +++ b/src/web/api/v1/contexts/torrent/responses.rs @@ -4,6 +4,7 @@ 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)] @@ -11,14 +12,16 @@ use crate::web::api::v1::responses::OkResponseData; 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> { +pub fn new_torrent_response(add_torrent_response: &AddTorrentResponse) -> Json> { 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(), }, }) }