fix: when restoring webdav, the current username, password and url are not preserved

This commit is contained in:
huzibaca 2024-11-25 03:41:35 +08:00
parent 39a3c3d3a7
commit 1cd1a2d907

View File

@ -464,6 +464,12 @@ pub async fn delete_webdav_backup(filename: String) -> Result<()> {
} }
pub async fn restore_webdav_backup(filename: String) -> Result<()> { pub async fn restore_webdav_backup(filename: String) -> Result<()> {
let verge = Config::verge();
let verge_data = verge.data().clone();
let webdav_url = verge_data.webdav_url.clone();
let webdav_username = verge_data.webdav_username.clone();
let webdav_password = verge_data.webdav_password.clone();
let backup_storage_path = app_home_dir().unwrap().join(&filename); let backup_storage_path = app_home_dir().unwrap().join(&filename);
backup::WebDavClient::global() backup::WebDavClient::global()
.download(filename, backup_storage_path.clone()) .download(filename, backup_storage_path.clone())
@ -477,6 +483,15 @@ pub async fn restore_webdav_backup(filename: String) -> Result<()> {
let mut zip = zip::ZipArchive::new(fs::File::open(backup_storage_path.clone())?)?; let mut zip = zip::ZipArchive::new(fs::File::open(backup_storage_path.clone())?)?;
zip.extract(app_home_dir()?)?; zip.extract(app_home_dir()?)?;
log_err!(
patch_verge(IVerge {
webdav_url: webdav_url,
webdav_username: webdav_username,
webdav_password: webdav_password,
..IVerge::default()
})
.await
);
// 最后删除临时文件 // 最后删除临时文件
fs::remove_file(backup_storage_path)?; fs::remove_file(backup_storage_path)?;
Ok(()) Ok(())