diff --git a/gossip-lib/src/blossom.rs b/gossip-lib/src/blossom.rs index 3b4c4525..0c7d2efc 100644 --- a/gossip-lib/src/blossom.rs +++ b/gossip-lib/src/blossom.rs @@ -113,11 +113,11 @@ impl Blossom { /// Check if the data exists on the blossom server pub async fn check_exists( &self, - host: String, + base_url: String, hash: HashOutput, authorize: bool, ) -> Result { - let url = format!("https://{}/{}", host, hash); + let url = format!("{}/{}", base_url, hash); let mut req_builder = self.client.head(url); if authorize { @@ -145,11 +145,11 @@ impl Blossom { /// with bytes(), bytes_stream(), chunk(), text(), or text_with_charset() pub async fn download( &self, - host: String, + base_url: String, hash: HashOutput, authorize: bool, ) -> Result { - let url = format!("https://{}/{}", host, hash); + let url = format!("{}/{}", base_url, hash); let mut req_builder = self.client.get(url); if authorize { @@ -181,7 +181,7 @@ impl Blossom { pub async fn upload>( &self, data: T, - host: String, + base_url: String, hash: HashOutput, content_type: Mime, content_length: u64, @@ -193,7 +193,7 @@ impl Blossom { vec![hash], )?; - let url = format!("https://{}/upload", host); + let url = format!("{}/upload", base_url); let response = self .client .put(url) diff --git a/gossip-lib/src/overlord.rs b/gossip-lib/src/overlord.rs index 4de8f3d3..b9675a9a 100644 --- a/gossip-lib/src/overlord.rs +++ b/gossip-lib/src/overlord.rs @@ -1035,11 +1035,24 @@ impl Overlord { } }; - let host = { + let base_url = { let blossom_servers = GLOBALS.db().read_setting_blossom_servers(); let first = blossom_servers.split_whitespace().next(); match first { - Some(bs) => bs.to_owned(), + Some(bs) => { + use http::uri::{Parts, PathAndQuery, Scheme}; + use http::Uri; + + let uri = bs.parse::()?; + let mut parts: Parts = uri.into_parts(); + parts.path_and_query = Some(PathAndQuery::from_static("/")); // Force no path + if parts.scheme.is_none() { + // Default to https + parts.scheme = Some(Scheme::HTTPS); + } + let uri = Uri::from_parts(parts)?; + format!("{}", uri) + } None => return Err(ErrorKind::General("Blossom not configured".to_owned()).into()), } }; @@ -1057,7 +1070,9 @@ impl Overlord { let file = tokio::fs::File::open(&pathbuf).await?; // upload - let result = blossom.upload(file, host, hash, mime, metadata.len()).await; + let result = blossom + .upload(file, base_url, hash, mime, metadata.len()) + .await; if let Ok(ref bd) = result { println!("UPLOADED: {} -> {}", pathbuf.display(), &bd.url); }