fix profile pictures on windows

This commit is contained in:
Josh Junon 2024-03-22 01:51:58 +01:00
parent 29a9e18b66
commit fdbf5a0184
No known key found for this signature in database

View File

@ -19,8 +19,6 @@ pub struct Proxy {
semaphores: sync::Arc<tokio::sync::Mutex<HashMap<url::Url, Semaphore>>>, semaphores: sync::Arc<tokio::sync::Mutex<HashMap<url::Url, Semaphore>>>,
} }
const ASSET_SCHEME: &str = "asset";
impl Proxy { impl Proxy {
pub fn new(cache_dir: path::PathBuf) -> Self { pub fn new(cache_dir: path::PathBuf) -> Self {
Proxy { Proxy {
@ -139,7 +137,12 @@ impl Proxy {
// takes a url of a remote assets, downloads it into cache and returns a url that points to the cached file // takes a url of a remote assets, downloads it into cache and returns a url that points to the cached file
pub async fn proxy(&self, src: &Url) -> Result<Url> { pub async fn proxy(&self, src: &Url) -> Result<Url> {
if src.scheme() == ASSET_SCHEME { #[cfg(unix)]
if src.scheme() == "asset" {
return Ok(src.clone());
}
if src.scheme() == "https" && src.host_str() == Some("asset.localhost") {
return Ok(src.clone()); return Ok(src.clone());
} }
@ -186,10 +189,15 @@ impl Proxy {
} }
} }
#[cfg(unix)]
fn build_asset_url(path: &str) -> Url {
Url::parse(&format!("asset://localhost/{}", urlencoding::encode(path))).unwrap()
}
#[cfg(windows)]
fn build_asset_url(path: &str) -> Url { fn build_asset_url(path: &str) -> Url {
Url::parse(&format!( Url::parse(&format!(
"{}://localhost/{}", "https://asset.localhost/{}",
ASSET_SCHEME,
urlencoding::encode(path) urlencoding::encode(path)
)) ))
.unwrap() .unwrap()