2025-03-01 22:52:43 +08:00
|
|
|
use super::CmdResult;
|
2025-03-13 12:51:20 +08:00
|
|
|
use crate::{config::*, core, feat, wrap_err};
|
2025-03-01 22:52:43 +08:00
|
|
|
use reqwest_dav::list_cmd::ListFile;
|
|
|
|
|
|
|
|
|
|
/// 保存 WebDAV 配置
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn save_webdav_config(url: String, username: String, password: String) -> CmdResult<()> {
|
|
|
|
|
let patch = IVerge {
|
|
|
|
|
webdav_url: Some(url),
|
|
|
|
|
webdav_username: Some(username),
|
|
|
|
|
webdav_password: Some(password),
|
|
|
|
|
..IVerge::default()
|
|
|
|
|
};
|
|
|
|
|
Config::verge()
|
2025-08-26 01:49:51 +08:00
|
|
|
.await
|
|
|
|
|
.draft_mut()
|
|
|
|
|
.patch_config(patch.clone());
|
|
|
|
|
Config::verge().await.apply();
|
|
|
|
|
|
|
|
|
|
// 分离数据获取和异步调用
|
|
|
|
|
let verge_data = Config::verge().await.latest_ref().clone();
|
|
|
|
|
verge_data
|
2025-03-01 22:52:43 +08:00
|
|
|
.save_file()
|
2025-08-26 01:49:51 +08:00
|
|
|
.await
|
2025-03-01 22:52:43 +08:00
|
|
|
.map_err(|err| err.to_string())?;
|
|
|
|
|
core::backup::WebDavClient::global().reset();
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 创建 WebDAV 备份并上传
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn create_webdav_backup() -> CmdResult<()> {
|
|
|
|
|
wrap_err!(feat::create_backup_and_upload_webdav().await)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 列出 WebDAV 上的备份文件
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn list_webdav_backup() -> CmdResult<Vec<ListFile>> {
|
|
|
|
|
wrap_err!(feat::list_wevdav_backup().await)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 删除 WebDAV 上的备份文件
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn delete_webdav_backup(filename: String) -> CmdResult<()> {
|
|
|
|
|
wrap_err!(feat::delete_webdav_backup(filename).await)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 从 WebDAV 恢复备份文件
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn restore_webdav_backup(filename: String) -> CmdResult<()> {
|
|
|
|
|
wrap_err!(feat::restore_webdav_backup(filename).await)
|
|
|
|
|
}
|