editer
This commit is contained in:
1 parent
ad987111a3
commit
c9e61f38c5
89 files changed
+11775
-3155
No files matched your search
@@ -0,0 +1,68 @@
|
||||
//! WebDAV 子模块:客户端与会话层。
|
||||
//!
|
||||
//! ```text
|
||||
//! client.rs ── 协议层:PROPFIND / MKCOL / GET / PUT / DELETE / MOVE(quick-xml 解析)
|
||||
//! mod.rs ── 会话层:读设置 → 取 keyring 密码 → 建客户端(供命令层一步调用)
|
||||
//! sync.rs ── 引擎层:清单比对 / 冲突策略 / 执行与基线维护
|
||||
//! ```
|
||||
//!
|
||||
//! 备份(zip 快照)在 `super::backup`:它只用 `PUT`,与同步是两条独立的路径
|
||||
//! (规划 §3.6 的取舍:对「只是要个备份」的用户,快照比双向同步可靠得多)。
|
||||
|
||||
pub mod client;
|
||||
pub mod sync;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
use crate::editor::types::WebdavSettings;
|
||||
use client::WebdavClient;
|
||||
|
||||
/// keyring 里的服务名(与 `secrets.rs` 的约定一致,服务名固定 `"Thing"`)。
|
||||
pub const KEYRING_PASSWORD: &str = "editor.webdav.password";
|
||||
|
||||
/// 连接自检结果(设置页展示)。
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WebdavTestResult {
|
||||
/// 是否连通
|
||||
pub ok: bool,
|
||||
/// 远端根目录中已有的条目数(自检时顺带列出)
|
||||
pub entries: u32,
|
||||
/// 本次自检自动创建的目录
|
||||
pub created: Vec<String>,
|
||||
/// 人话结论(失败时是原因)
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
/// 由设置构造客户端(密码从 keyring 取,**不落盘**)。
|
||||
///
|
||||
/// 密码走系统凭据管理器而不是 `settings.json`:设置文件是明文 JSON,用户可能把库
|
||||
/// 连同设置一起放到同步目录里(那就等于把密码公开了)。keyring 的键是
|
||||
/// [`KEYRING_PASSWORD`],服务名沿用项目统一的 `"Thing"`。
|
||||
pub fn client_from(settings: &WebdavSettings) -> Result<WebdavClient, String> {
|
||||
settings.validate()?;
|
||||
let password = crate::secrets::secret_read(KEYRING_PASSWORD)
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_default();
|
||||
WebdavClient::new(client::WebdavConfig {
|
||||
url: settings.url.trim().to_string(),
|
||||
username: settings.username.trim().to_string(),
|
||||
password,
|
||||
remote_root: settings.remote_root.trim().to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
/// 连接自检:验证地址/凭据,并按需逐级创建远端根目录。
|
||||
pub fn test_connection(settings: &WebdavSettings) -> Result<WebdavTestResult, String> {
|
||||
let client = client_from(settings)?;
|
||||
let created = client.ensure_root()?;
|
||||
let entries = client.list_recursive()?.len() as u32;
|
||||
Ok(WebdavTestResult {
|
||||
ok: true,
|
||||
entries,
|
||||
created,
|
||||
message: format!("连接正常,远端已有 {entries} 个文件"),
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user