libsubconverter/utils/
file.rs1use crate::settings::Settings;
2use crate::utils::http::{parse_proxy, web_get_async};
3
4#[cfg(not(target_arch = "wasm32"))]
6mod platform {
7 pub use crate::utils::file_std::{copy_file, file_exists, file_get_async, read_file_async};
8}
9
10#[cfg(target_arch = "wasm32")]
11mod platform {
12 pub use crate::utils::file_wasm::{copy_file, file_exists, file_get_async, read_file_async};
13}
14
15pub use platform::*;
17
18pub async fn load_content_async(path: &str) -> Result<String, String> {
29 if path.starts_with("http://") || path.starts_with("https://") {
30 match web_get_async(path, &parse_proxy(&Settings::current().proxy_config), None).await {
32 Ok(response) => Ok(response.body),
33 Err(e) => Err(format!("Failed to read file from URL: {}", e)),
34 }
35 } else if file_exists(path).await {
36 match read_file_async(path).await {
38 Ok(data) => Ok(data),
39 Err(e) => Err(format!("Failed to read file: {}", e)),
40 }
41 } else {
42 Err(format!("Path not found: {}", path))
43 }
44}