fix
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
"opener:default",
|
||||
"opener:allow-open-path"
|
||||
]
|
||||
}
|
||||
|
||||
+35
-1
@@ -55,6 +55,39 @@ async fn sync_contracts(
|
||||
sync::sync_contracts(&api, app_data_dir).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn load_application_file(local_path: String, scan_url: String) -> Result<Vec<u8>, ApiError> {
|
||||
if !local_path.is_empty() {
|
||||
match tokio::fs::metadata(&local_path).await {
|
||||
Ok(metadata) if metadata.len() > 0 => {
|
||||
return tokio::fs::read(&local_path)
|
||||
.await
|
||||
.map_err(|error| ApiError::new("file_error", error.to_string()));
|
||||
}
|
||||
Ok(_) | Err(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
if scan_url.is_empty() {
|
||||
return Err(ApiError::new("file_error", "Файл недоступен"));
|
||||
}
|
||||
|
||||
let response = reqwest::Client::new().get(&scan_url).send().await?;
|
||||
if !response.status().is_success() {
|
||||
return Err(ApiError::new(
|
||||
"remote_error",
|
||||
format!("file download failed with {}", response.status()),
|
||||
));
|
||||
}
|
||||
|
||||
let bytes = response.bytes().await?;
|
||||
if bytes.is_empty() {
|
||||
return Err(ApiError::new("file_error", "Файл пустой"));
|
||||
}
|
||||
|
||||
Ok(bytes.to_vec())
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -83,7 +116,8 @@ pub fn run() {
|
||||
auth_set_token,
|
||||
auth_logout,
|
||||
auth_status,
|
||||
sync_contracts
|
||||
sync_contracts,
|
||||
load_application_file
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user