Skip to content

Commit

Permalink
Remove stub impl of ContentDirectoryBrowseProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Sep 2, 2024
1 parent 0cb34d9 commit f96a902
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
22 changes: 19 additions & 3 deletions crates/upnp-serve/examples/upnp-stub-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@ use std::{
use anyhow::Context;
use axum::routing::get;
use librqbit_upnp_serve::{
services::content_directory::browse::response::{Item, ItemOrContainer},
services::content_directory::{
browse::response::{Item, ItemOrContainer},
ContentDirectoryBrowseProvider,
},
UpnpServer, UpnpServerOptions,
};
use mime_guess::Mime;
use tracing::{error, info};

struct VecWrap(Vec<ItemOrContainer>);

impl ContentDirectoryBrowseProvider for VecWrap {
fn browse_direct_children(&self, _parent_id: usize, _http_host: &str) -> Vec<ItemOrContainer> {
self.0.clone()
}

fn browse_metadata(&self, _object_id: usize, _http_hostname: &str) -> Vec<ItemOrContainer> {
// TODO. Remove the vec provider from core code.
vec![]
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
if std::env::var("RUST_LOG").is_err() {
Expand All @@ -20,14 +36,14 @@ async fn main() -> anyhow::Result<()> {

tracing_subscriber::fmt::init();

let items: Vec<ItemOrContainer> = vec![ItemOrContainer::Item(Item {
let items = VecWrap(vec![ItemOrContainer::Item(Item {
title: "Example".to_owned(),
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: 0,
size: 1,
})];
})]);

const HTTP_PORT: u16 = 9005;
const HTTP_PREFIX: &str = "/upnp";
Expand Down
14 changes: 3 additions & 11 deletions crates/upnp-serve/src/services/content_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ pub mod browse {
</DIDL-Lite>"#,
items = envelope.items
);

// This COULD have been done with CDATA, but some Samsung TVs don't like that, they want
// escaped XML instead.
let items_encoded = quick_xml::escape::escape(items_encoded.as_ref());

format!(
Expand Down Expand Up @@ -339,17 +342,6 @@ pub trait ContentDirectoryBrowseProvider: Send + Sync {
fn browse_metadata(&self, object_id: usize, http_hostname: &str) -> Vec<ItemOrContainer>;
}

impl ContentDirectoryBrowseProvider for Vec<ItemOrContainer> {
fn browse_direct_children(&self, _parent_id: usize, _http_host: &str) -> Vec<ItemOrContainer> {
self.clone()
}

fn browse_metadata(&self, _object_id: usize, _http_hostname: &str) -> Vec<ItemOrContainer> {
// TODO. Remove the vec provider from core code.
vec![]
}
}

#[cfg(test)]
mod tests {
#[test]
Expand Down

0 comments on commit f96a902

Please sign in to comment.