1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-07-30 22:07:01 +00:00

terminal: handle ipv6 addressed correctly when formatting URLs

This commit is contained in:
Marcus 2024-10-12 17:52:14 +02:00 committed by Michael Hollister
parent c5259ee07f
commit 1cd91f91e9

View file

@ -247,7 +247,6 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
let url = result.0;
join_handle = Some(result.1);
//TODO: Make this work
PlayMessage::new(
mime_type,
Some(url),
@ -366,8 +365,13 @@ impl ServerState {
}
fn host_file_and_get_url(local_ip: &IpAddr, file_path: &str, mime_type: &String, running: &Arc<AtomicBool>) -> Result<(String, thread::JoinHandle<Result<(), String>>), String> {
let local_ip_str = if local_ip.is_ipv6() {
format!("[{}]", local_ip)
} else {
format!("{}", local_ip)
};
let server = {
let this = Server::http(format!("{}:0", local_ip));
let this = Server::http(format!("{local_ip_str}:0"));
match this {
Ok(t) => Ok(t),
Err(e) => Err((|e| format!("Failed to create server: {}", e))(e)),
@ -375,7 +379,7 @@ fn host_file_and_get_url(local_ip: &IpAddr, file_path: &str, mime_type: &String,
}?;
let url = match server.server_addr() {
ListenAddr::IP(addr) => format!("http://{}:{}/", local_ip, addr.port()),
ListenAddr::IP(addr) => format!("http://{local_ip_str}:{}/", addr.port()),
#[cfg(unix)]
ListenAddr::Unix(_) => return Err("Unix socket addresses are not supported.".to_string()),
};