use crate::settings::Settings;
use crate::utils::http::{parse_proxy, web_get_async};
#[cfg(not(target_arch = "wasm32"))]
mod platform {
pub use crate::utils::file_std::{copy_file, file_exists, file_get_async, read_file_async};
}
#[cfg(target_arch = "wasm32")]
mod platform {
pub use crate::utils::file_wasm::{copy_file, file_exists, file_get_async, read_file_async};
}
pub use platform::*;
pub async fn load_content_async(path: &str) -> Result<String, String> {
if path.starts_with("http://") || path.starts_with("https://") {
match web_get_async(path, &parse_proxy(&Settings::current().proxy_config), None).await {
Ok(response) => Ok(response.body),
Err(e) => Err(format!("Failed to read file from URL: {}", e)),
}
} else if file_exists(path).await {
match read_file_async(path).await {
Ok(data) => Ok(data),
Err(e) => Err(format!("Failed to read file: {}", e)),
}
} else {
Err(format!("Path not found: {}", path))
}
}