From 79a84515196266b85b2b4b668af4952ba323bc83 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Sat, 31 Aug 2024 19:09:59 +0100 Subject: [PATCH] Implement parent_id=-1 --- crates/librqbit/src/upnp_server_adapter.rs | 12 ++++++------ crates/upnp-serve/examples/upnp-stub-server.rs | 2 +- crates/upnp-serve/src/services/content_directory.rs | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/librqbit/src/upnp_server_adapter.rs b/crates/librqbit/src/upnp_server_adapter.rs index 3128930..d0370ff 100644 --- a/crates/librqbit/src/upnp_server_adapter.rs +++ b/crates/librqbit/src/upnp_server_adapter.rs @@ -74,7 +74,7 @@ impl TorrentFileTreeNode { .unwrap_or_else(|| self.title.clone()); ItemOrContainer::Item(Item { id: encoded_id, - parent_id: encoded_parent_id.map(|id| id as isize), + parent_id: encoded_parent_id.unwrap_or_default(), title: self.title.clone(), mime_type: mime_guess::from_path(filename).first(), url: format!( @@ -124,7 +124,7 @@ impl TorrentFileTree { .context("bug")??; let root_node = TorrentFileTreeNode { title: filename.to_owned(), - parent_id: None, + parent_id: Some(0), children: vec![], real_torrent_file_id: Some(0), }; @@ -220,7 +220,7 @@ impl UpnpServerSessionAdapter { ); Some(ItemOrContainer::Item(Item { id: upnp_id, - parent_id: None, + parent_id: 0, title, mime_type, url, @@ -238,7 +238,7 @@ impl UpnpServerSessionAdapter { // Create a folder Some(ItemOrContainer::Container(Container { id: upnp_id, - parent_id: None, + parent_id: Some(0), title, children_count: None, })) @@ -572,14 +572,14 @@ mod tests { vec![ ItemOrContainer::Item(Item { id: encode_id(0, 0), - parent_id: None, + parent_id: Some(0), title: "f1".into(), mime_type: None, url: "http://127.0.0.1:9005/torrents/0/stream/0/f1".into() }), ItemOrContainer::Container(Container { id: encode_id(0, 1), - parent_id: None, + parent_id: Some(0), children_count: None, title: "t2".into() }) diff --git a/crates/upnp-serve/examples/upnp-stub-server.rs b/crates/upnp-serve/examples/upnp-stub-server.rs index efb768b..51a44a6 100644 --- a/crates/upnp-serve/examples/upnp-stub-server.rs +++ b/crates/upnp-serve/examples/upnp-stub-server.rs @@ -25,7 +25,7 @@ async fn main() -> anyhow::Result<()> { mime_type: Some(Mime::from_str("video/x-matroska")?), url: "http://192.168.0.165:3030/torrents/4/stream/0/file.mkv".to_owned(), id: 1, - parent_id: Some(0), + parent_id: 0, })]; const HTTP_PORT: u16 = 9005; diff --git a/crates/upnp-serve/src/services/content_directory.rs b/crates/upnp-serve/src/services/content_directory.rs index 515a7ef..b04e624 100644 --- a/crates/upnp-serve/src/services/content_directory.rs +++ b/crates/upnp-serve/src/services/content_directory.rs @@ -70,7 +70,7 @@ pub mod browse { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Item { pub id: usize, - pub parent_id: Option, + pub parent_id: usize, pub title: String, pub mime_type: Option, pub url: String, @@ -97,7 +97,7 @@ pub mod browse { "../resources/templates/content_directory/control/browse/item.tmpl.xml" ), id = item.id, - parent_id = item.parent_id.unwrap_or(-1), + parent_id = item.parent_id, mime_type = mime, url = item.url, upnp_class = upnp_class, @@ -115,7 +115,7 @@ pub mod browse { "../resources/templates/content_directory/control/browse/container.tmpl.xml" ), id = item.id, - parent_id = item.parent_id.unwrap_or(0), + parent_id = item.parent_id.map(|p| p as isize).unwrap_or(-1), title = item.title, childCountTag = child_count_tag )