Fix desktop to support this

This commit is contained in:
Igor Katson 2024-08-28 13:56:12 +01:00
parent d90c4dabe7
commit fef068d809
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
6 changed files with 27 additions and 29 deletions

View file

@ -135,9 +135,6 @@ pub struct RqbitDesktopConfigUpnp {
#[serde(default)]
pub enable_server: bool,
#[serde(default)]
pub server_hostname: Option<String>,
#[serde(default)]
pub server_friendly_name: Option<String>,
}
@ -183,12 +180,6 @@ impl RqbitDesktopConfig {
if self.http_api.listen_addr.ip().is_loopback() {
anyhow::bail!("if UPnP server is enabled, you need to set HTTP API IP to 0.0.0.0 or at least non-localhost address.")
}
match self.upnp.server_hostname.as_ref().map(|s| s.trim()) {
Some("") | None => {
anyhow::bail!("UPnP hostname must be set to non-empty string")
}
Some(_) => {}
}
}
Ok(())
}

View file

@ -122,13 +122,6 @@ async fn api_from_config(
let api = api.clone();
let read_only = config.http_api.read_only;
let upnp_router = if config.upnp.enable_server {
let hostname = config
.upnp
.server_hostname
.as_ref()
.map(|h| h.trim())
.context("empty UPNP hostname")?
.to_owned();
let friendly_name = config
.upnp
.server_friendly_name
@ -136,10 +129,15 @@ async fn api_from_config(
.map(|f| f.trim())
.filter(|s| !s.is_empty())
.map(|s| s.to_owned())
.unwrap_or_else(|| format!("rqbit@{hostname}"));
.unwrap_or_else(|| {
format!(
"rqbit-desktop@{}",
gethostname::gethostname().to_string_lossy()
)
});
let mut upnp_adapter = session
.make_upnp_adapter(friendly_name, hostname, config.http_api.listen_addr.port())
.make_upnp_adapter(friendly_name, config.http_api.listen_addr.port())
.await
.context("error starting UPnP server")?;
let router = upnp_adapter.take_router()?;