Skip to content

World's first open-source enterprise world model.

A WebDAV share is a source, and the namespace prefix is nobody's business (#209)

WaylandYang43cb7f8e36e9
diff --git a/Cargo.lock b/Cargo.lock
index 66810570..4fd49555 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2582,6 +2582,7 @@ dependencies = [
"futures-util",
"http",
"http-body-util",
+ "httparse",
"humantime",
"hyper",
"itertools 0.15.0",
@@ -4928,6 +4929,7 @@ dependencies = [
"futures-util",
"jsonwebtoken",
"object_store",
+ "quick-xml 0.42.0",
"reqwest",
"serde",
"serde_json",
diff --git a/crates/utopia-server/Cargo.toml b/crates/utopia-server/Cargo.toml
index e564ecf6..ffd2b546 100644
--- a/crates/utopia-server/Cargo.toml
+++ b/crates/utopia-server/Cargo.toml
@@ -40,3 +40,4 @@ feed-rs.workspace = true
async-trait = "0.1.92"
sqlparser = "0.62.0"
object_store = { version = "0.14.1", features = ["aws", "azure", "gcp"] }
+quick-xml.workspace = true
diff --git a/crates/utopia-server/src/ingest_sources.rs b/crates/utopia-server/src/ingest_sources.rs
index 4d6085bc..936c0e87 100644
--- a/crates/utopia-server/src/ingest_sources.rs
+++ b/crates/utopia-server/src/ingest_sources.rs
@@ -55,6 +55,7 @@ pub async fn sync_source(state: &AppState, source_id: Uuid) -> anyhow::Result<()
"github_issues" => sync_github_issues(state, &source).await,
"jira_issues" => sync_jira_issues(state, &source).await,
"s3" | "azure_blob" | "gcs" => sync_object_storage(state, &source).await,
+ "webdav" => sync_webdav(state, &source).await,
// folder / api 无拉取语义
_ => Ok(SyncStats::default()),
};
@@ -804,6 +805,51 @@ async fn sync_object_storage(state: &AppState, source: &Source) -> anyhow::Resul
Ok(stats)
}
+/// WebDAV 同步:逐层走目录,把文件摄进来。
+///
+/// `external_key` 用 `webdav://host/path`——同一台网盘换了挂载点仍是同一份
+/// 文件,而不同网盘上的同名路径是两份。
+async fn sync_webdav(state: &AppState, source: &Source) -> anyhow::Result<SyncStats> {
+ let base = source.config["base_url"]
+ .as_str()
+ .map(str::trim)
+ .filter(|s| !s.is_empty())
+ .ok_or_else(|| anyhow::anyhow!("webdav source is missing config.base_url"))?;
+ let root = source.config["path"].as_str().map(str::trim).unwrap_or("/");
+ let user = source.config["username"].as_str().map(str::trim);
+ let pass = source.config["password"].as_str().map(str::trim);
+ let auth = match (user, pass) {
+ (Some(u), Some(p)) if !u.is_empty() => Some((u, p)),
+ _ => None,
+ };
+
+ let http = reqwest::Client::builder()
+ .timeout(std::time::Duration::from_secs(60))
+ .build()?;
+ let (files, truncated) = crate::webdav::fetch(&http, base, root, auth).await?;
+ if truncated {
+ tracing::warn!(base, root, "文件数到达单次上限,其余留给下一次同步");
+ }
+
+ let mut stats = SyncStats::default();
+ for f in files {
+ // 不猜 mime,理由同对象存储:解析先看魔数
+ let action = ingest_item(
+ state,
+ source.kb_id,
+ source.id,
+ &f.external_key,
+ &f.filename,
+ "application/octet-stream",
+ &f.bytes,
+ f.last_modified,
+ )
+ .await?;
+ stats.absorb(action);
+ }
+ Ok(stats)
+}
+
/// 标题无扩展名时按 mime 补一个,接入解析矩阵的分派。
fn ensure_extension(title: &str, mime: &str) -> String {
let has_ext = title
diff --git a/crates/utopia-server/src/main.rs b/crates/utopia-server/src/main.rs
index 5d2b69d3..8cf85a8c 100644
--- a/crates/utopia-server/src/main.rs
+++ b/crates/utopia-server/src/main.rs
@@ -25,6 +25,7 @@ mod query_engine;
mod retrieval;
mod state;
mod type_resolution;
+mod webdav;
use state::AppState;
use std::sync::Arc;
diff --git a/crates/utopia-server/src/webdav.rs b/crates/utopia-server/src/webdav.rs
new file mode 100644
index 00000000..8b0584a0
--- /dev/null
+++ b/crates/utopia-server/src/webdav.rs
@@ -0,0 +1,396 @@
+//! WebDAV 来源:Nextcloud、ownCloud、坚果云、群晖、Apache mod_dav、
+//! rclone serve webdav,以及一切说这套协议的网盘。
+//!
+//! 按 [0013](../../docs/decisions/0013-a-source-should-hand-over-its-history.md)
+//! 的四条判据,它跟对象存储是同一档:有 `getlastmodified`、身份是路径、
+//! 企业里确实有一堆文档住在网盘上;而「会不会自我推翻」只能靠两次同步的
+//! 差异看出来——WebDAV 的版本控制扩展(RFC 3253)几乎没有服务端实现。
+//!
+//! **不引 WebDAV 客户端库。** 这套协议要的东西很窄:一个 `PROPFIND` 拿列表、
+//! 一个 `GET` 取内容,响应是 XML。`reqwest` 与 `quick-xml` 都已经在树里,
+//! 加起来零新增依赖;而现有的 dav 客户端 crate 要么裹着自己的 HTTP 栈,
+//! 要么把整套 RFC 4918(锁、属性写、版本)都拖进来,而那些我们一条都不用。
+
+use anyhow::Context as _;
+use chrono::{DateTime, Utc};
+use quick_xml::events::Event;
+use quick_xml::Reader;
+
+/// 一次同步最多摄入多少个文件。理由与对象存储那边相同:网盘也能装下
+/// 十万个文件,而摄入不可逆。
+const MAX_FILES_PER_SYNC: usize = 2_000;
+
+/// 单个文件的大小上限。
+const MAX_FILE_BYTES: u64 = 32 * 1024 * 1024;
+
+/// 目录递归的层数上限。**不是怕深,是怕环**:有些服务端会把符号链接
+/// 或共享目录暴露成可以自己指向自己的路径,`Depth: infinity` 在那种目录上
+/// 永远回不来。逐层走并且封顶,比信任服务端安全。
+const MAX_DEPTH: usize = 8;
+
+/// 一个远端文件。
+pub struct RemoteFile {
+ /// `webdav://host/path`——`ingest_item` 的 external_key 约定是 URI 形态
+ pub external_key: String,
+ pub filename: String,
+ pub bytes: Vec<u8>,
+ pub last_modified: Option<DateTime<Utc>>,
+}
+
+/// `PROPFIND` 回来的一条。
+#[derive(Debug, PartialEq)]
+struct Entry {
+ /// 服务端给的 href,已解码
+ href: String,
+ is_dir: bool,
+ len: u64,
+ modified: Option<DateTime<Utc>>,
+}
+
+/// 解析 `multistatus` 响应。
+///
+/// **只认本地名,不认前缀。** 服务端可能用 `D:`、`d:`、`ns0:`,也可能干脆
+/// 不加前缀——RFC 允许任意前缀绑到 `DAV:` 命名空间上。按 `d:response` 这样
+/// 硬匹配的解析器,换一台服务端就一条都读不出来,而症状是「同步成功,
+/// 零个文件」。
+///
+/// **目录判据是 `<collection/>` 存在,不是 href 以 `/` 结尾。** 后者是约定
+/// 不是规范,而 rclone 与 Nextcloud 在这一点上就不一致。
+fn parse_multistatus(xml: &str) -> anyhow::Result<Vec<Entry>> {
+ let mut r = Reader::from_str(xml);
+ r.config_mut().trim_text(true);
+
+ let mut out = Vec::new();
+ let mut cur: Option<Entry> = None;
+ let mut field = String::new();
+ let mut buf = Vec::new();
+
+ loop {
+ match r.read_event_into(&mut buf) {
+ Ok(Event::Start(e)) => {
+ let name = local_name(e.name().into_inner());
+ match name.as_str() {
+ "response" => {
+ cur = Some(Entry {
+ href: String::new(),
+ is_dir: false,
+ len: 0,
+ modified: None,
+ });
+ }
+ "collection" => {
+ if let Some(c) = cur.as_mut() {
+ c.is_dir = true;
+ }
+ }
+ other => field = other.to_string(),
+ }
+ }
+ // `<collection/>` 通常是自闭合标签,走 Empty 而不是 Start——
+ // 少了这一条,所有目录都会被当成文件去 GET
+ Ok(Event::Empty(e)) => {
+ if local_name(e.name().into_inner()) == "collection" {
+ if let Some(c) = cur.as_mut() {
+ c.is_dir = true;
+ }
+ }
+ }
+ Ok(Event::Text(t)) => {
+ let Some(c) = cur.as_mut() else { continue };
+ let v = t
+ .xml_content(quick_xml::XmlVersion::Implicit1_0)
+ .to_string();
+ match field.as_str() {
+ "href" => c.href = percent_decode(&v),
+ "getcontentlength" => c.len = v.trim().parse().unwrap_or(0),
+ "getlastmodified" => {
+ // RFC 1123,`Wed, 02 Sep 2026 15:04:05 GMT`
+ c.modified = DateTime::parse_from_rfc2822(v.trim())
+ .ok()
+ .map(|d| d.with_timezone(&Utc));
+ }
+ _ => {}
+ }
+ }
+ Ok(Event::End(e)) => {
+ if local_name(e.name().into_inner()) == "response" {
+ if let Some(c) = cur.take() {
+ out.push(c);
+ }
+ }
+ field.clear();
+ }
+ Ok(Event::Eof) => break,
+ Err(e) => return Err(anyhow::anyhow!("PROPFIND 响应解析失败: {e}")),
+ _ => {}
+ }
+ buf.clear();
+ }
+ Ok(out)
+}
+
+/// 取标签的本地名,丢掉命名空间前缀并转小写。
+///
+/// 规范说元素名区分大小写,但实测有服务端写 `getLastModified`。
+/// 前缀也自己切:`D:`、`d:`、`ns0:` 都合法,RFC 允许任意前缀绑到 `DAV:`。
+fn local_name(raw: &str) -> String {
+ raw.rsplit(':').next().unwrap_or(raw).to_ascii_lowercase()
+}
+
+/// href 里的百分号转义。
+///
+/// 自己解而不是引 `percent-encoding`:这里只需要解码,而解码是十来行。
+/// 非法序列原样留下——href 是拿来拼 URL 的,猜错了不如不动。
+fn percent_decode(s: &str) -> String {
+ let b = s.as_bytes();
+ let mut out = Vec::with_capacity(b.len());
+ let mut i = 0;
+ while i < b.len() {
+ if b[i] == b'%' && i + 2 < b.len() {
+ let hex = std::str::from_utf8(&b[i + 1..i + 3]).ok();
+ if let Some(v) = hex.and_then(|h| u8::from_str_radix(h, 16).ok()) {
+ out.push(v);
+ i += 3;
+ continue;
+ }
+ }
+ out.push(b[i]);
+ i += 1;
+ }
+ String::from_utf8_lossy(&out).into_owned()
+}
+
+/// 逐层走目录,取回所有文件。
+///
+/// **不用 `Depth: infinity`。** 规范允许服务端拒绝它(`403 Propfind-Finite-Depth`),
+/// 而 Nextcloud 与 Apache mod_dav 默认就是拒绝的;能接受它的服务端在大目录上
+/// 又会一次性吐出几十兆 XML。逐层加封顶,两头的问题都没有。
+pub async fn fetch(
+ http: &reqwest::Client,
+ base: &str,
+ root: &str,
+ auth: Option<(&str, &str)>,
+) -> anyhow::Result<(Vec<RemoteFile>, bool)> {
+ let host = reqwest::Url::parse(base)
+ .ok()
+ .and_then(|u| u.host_str().map(str::to_string))
+ .unwrap_or_else(|| "webdav".into());
+ let base = base.trim_end_matches('/').to_string();
+
+ let mut out = Vec::new();
+ let mut truncated = false;
+ let mut queue = vec![(normalize(root), 0usize)];
+ let mut unreadable = 0usize;
+
+ while let Some((dir, depth)) = queue.pop() {
+ if depth > MAX_DEPTH {
+ tracing::warn!(%dir, "目录太深,不再往下");
+ continue;
+ }
+ let url = format!("{base}{dir}");
+ let mut req = http
+ .request(reqwest::Method::from_bytes(b"PROPFIND").unwrap(), &url)
+ .header("Depth", "1")
+ .header("Content-Type", "application/xml");
+ if let Some((u, p)) = auth {
+ req = req.basic_auth(u, Some(p));
+ }
+ let resp = req
+ .send()
+ .await
+ .with_context(|| format!("PROPFIND {url}"))?;
+ if !resp.status().is_success() {
+ anyhow::bail!("PROPFIND {url} 回了 {}", resp.status());
+ }
+ let xml = resp.text().await.context("读取 PROPFIND 响应")?;
+
+ for e in parse_multistatus(&xml)? {
+ let path = normalize(&strip_base(&e.href, &base));
+ // 服务端会把被查询的目录自己也列进来,跳过它否则会无限打转
+ if path == dir {
+ continue;
+ }
+ if e.is_dir {
+ queue.push((path, depth + 1));
+ continue;
+ }
+ if e.len == 0 || e.len > MAX_FILE_BYTES {
+ continue;
+ }
+ if out.len() >= MAX_FILES_PER_SYNC {
+ truncated = true;
+ break;
+ }
+
+ // 一个文件取不回来不该带走整次同步——与对象存储那边同一个判断
+ let mut g = http.get(format!("{base}{path}"));
+ if let Some((u, p)) = auth {
+ g = g.basic_auth(u, Some(p));
+ }
+ let got = async {
+ let r = g.send().await?;
+ if !r.status().is_success() {
+ anyhow::bail!("{}", r.status());
+ }
+ Ok::<_, anyhow::Error>(r.bytes().await?)
+ }
+ .await;
+ let bytes = match got {
+ Ok(b) => b,
+ Err(err) => {
+ unreadable += 1;
+ tracing::warn!(%path, error = %err, "文件取不回来,跳过");
+ continue;
+ }
+ };
+
+ out.push(RemoteFile {
+ external_key: format!("webdav://{host}{path}"),
+ filename: path.rsplit('/').next().unwrap_or(&path).to_string(),
+ bytes: bytes.to_vec(),
+ last_modified: e.modified,
+ });
+ }
+ if truncated {
+ break;
+ }
+ }
+ if unreadable > 0 {
+ tracing::warn!(unreadable, "有文件没能取回");
+ }
+ Ok((out, truncated))
+}
+
+/// 路径统一成 `/a/b` 的形状:前有斜杠、后无斜杠(根除外)。
+fn normalize(p: &str) -> String {
+ let t = p.trim();
+ let t = t.strip_suffix('/').unwrap_or(t);
+ if t.is_empty() {
+ "/".into()
+ } else if t.starts_with('/') {
+ t.into()
+ } else {
+ format!("/{t}")
+ }
+}
+
+/// href 可能是绝对 URL 也可能只是路径——两种都合法,服务端各写各的。
+fn strip_base(href: &str, base: &str) -> String {
+ if let Some(rest) = href.strip_prefix(base) {
+ return rest.to_string();
+ }
+ // 绝对但换了主机名(反代改写过):退回取它的 path
+ if href.starts_with("http://") || href.starts_with("https://") {
+ if let Ok(u) = reqwest::Url::parse(href) {
+ return u.path().to_string();
+ }
+ }
+ href.to_string()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// **命名空间前缀是任意的。** 同一份响应换个前缀必须解出同样的东西,
+ /// 否则换一台服务端就「同步成功,零个文件」——最难查的那种失败。
+ #[test]
+ fn any_namespace_prefix_parses_the_same() {
+ let with_d = r#"<?xml version="1.0"?>
+<D:multistatus xmlns:D="DAV:"><D:response>
+ <D:href>/docs/a.txt</D:href>
+ <D:propstat><D:prop>
+ <D:getcontentlength>5</D:getcontentlength>
+ <D:getlastmodified>Wed, 02 Sep 2026 15:04:05 GMT</D:getlastmodified>
+ <D:resourcetype/>
+ </D:prop></D:propstat>
+</D:response></D:multistatus>"#;
+ // 前缀换掉,命名空间声明本身不受影响(`xmlns:D="DAV:"` 里没有 `D:` 这个子串)
+ let with_ns0 = with_d.replace("D:", "ns0:");
+ let a = parse_multistatus(with_d).unwrap();
+ let b = parse_multistatus(&with_ns0).unwrap();
+ assert_eq!(a, b, "换个前缀就解不出来了");
+ assert_eq!(a.len(), 1);
+ assert_eq!(a[0].href, "/docs/a.txt");
+ assert_eq!(a[0].len, 5);
+ assert!(!a[0].is_dir);
+ assert!(
+ a[0].modified.is_some(),
+ "getlastmodified 是 doc_time 的来源"
+ );
+ }
+
+ /// **目录判据是 `<collection/>`,而它通常是自闭合标签。**
+ /// 只处理 `Event::Start` 的解析器会把每个目录都当成文件去 GET。
+ #[test]
+ fn a_self_closing_collection_is_still_a_directory() {
+ let xml = r#"<multistatus xmlns="DAV:"><response>
+ <href>/docs/</href>
+ <propstat><prop><resourcetype><collection/></resourcetype></prop></propstat>
+</response></multistatus>"#;
+ let e = parse_multistatus(xml).unwrap();
+ assert!(e[0].is_dir, "自闭合的 collection 没被认出来");
+ }
+
+ /// href 是百分号转义过的,中文路径直接拼 URL 会 404。
+ #[test]
+ fn a_percent_encoded_href_is_decoded() {
+ assert_eq!(
+ percent_decode("/docs/%E4%B8%AD%E6%96%87.txt"),
+ "/docs/中文.txt"
+ );
+ // 非法序列原样留着,不猜
+ assert_eq!(percent_decode("/a%ZZb"), "/a%ZZb");
+ }
+
+ /// 路径统一:前有斜杠、后无斜杠。两端不一致会让同一个目录被走两遍。
+ #[test]
+ fn paths_normalise_to_one_shape() {
+ for (raw, want) in [
+ ("docs", "/docs"),
+ ("/docs/", "/docs"),
+ ("/", "/"),
+ ("", "/"),
+ ] {
+ assert_eq!(normalize(raw), want, "{raw}");
+ }
+ }
+
+ /// 真连一个 WebDAV 服务端。没有 `UTOPIA_DAV_TEST_URL` 就跳过。
+ ///
+ /// 用 rclone 起一个最省事,它和 Nextcloud 在 href 形态上不一样,
+ /// 正好能验解析不挑服务端:
+ /// ```text
+ /// mkdir -p /tmp/dav/docs && echo hello > /tmp/dav/docs/a.txt
+ /// rclone serve webdav /tmp/dav --addr 127.0.0.1:18081 --user u --pass p
+ /// UTOPIA_DAV_TEST_URL=http://127.0.0.1:18081 UTOPIA_DAV_TEST_USER=u /// UTOPIA_DAV_TEST_PASS=p cargo test -p utopia-server webdav
+ /// ```
+ #[tokio::test]
+ async fn it_reads_from_a_real_webdav_server() -> anyhow::Result<()> {
+ let Ok(base) = std::env::var("UTOPIA_DAV_TEST_URL") else {
+ eprintln!("跳过:未设 UTOPIA_DAV_TEST_URL");
+ return Ok(());
+ };
+ let user = std::env::var("UTOPIA_DAV_TEST_USER").unwrap_or_default();
+ let pass = std::env::var("UTOPIA_DAV_TEST_PASS").unwrap_or_default();
+ let auth = (!user.is_empty()).then_some((user.as_str(), pass.as_str()));
+
+ let http = reqwest::Client::builder()
+ .timeout(std::time::Duration::from_secs(30))
+ .build()?;
+ let (files, truncated) = fetch(&http, &base, "/docs", auth).await?;
+ assert!(!truncated);
+
+ let a = files.iter().find(|f| f.filename == "a.txt").expect("a.txt");
+ assert_eq!(a.bytes, b"hello from webdav");
+ assert!(
+ a.external_key.starts_with("webdav://"),
+ "{}",
+ a.external_key
+ );
+ assert!(a.last_modified.is_some());
+ // 目录本身不该混进来
+ assert!(files.iter().all(|f| !f.filename.is_empty()));
+ Ok(())
+ }
+}
diff --git a/web/src/api.ts b/web/src/api.ts
index 6db228da..bf46b22a 100644
--- a/web/src/api.ts
+++ b/web/src/api.ts
@@ -188,6 +188,7 @@ export interface SourceView {
| "s3"
| "azure_blob"
| "gcs"
+ | "webdav"
| "memory"
| "upload";
name: string;
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index dc585c9c..c21e6bcb 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -462,6 +462,7 @@ export const en = {
s3: "S3 / MinIO",
azure_blob: "Azure Blob",
gcs: "Google Cloud Storage",
+ webdav: "WebDAV",
},
sourceKindHints: {
folder:
@@ -486,6 +487,10 @@ export const en = {
gcs:
"Reads documents out of a Google Cloud Storage bucket. The service account JSON " +
"goes in whole — there is no file on the server to point at.",
+ webdav:
+ "Reads documents off a WebDAV share — Nextcloud, ownCloud, Synology, or anything " +
+ "else speaking the protocol. Walks folders one level at a time; each file becomes " +
+ "a document dated by its last modification.",
api: "External systems push JSON documents here, authenticated with this source's own token.",
custom:
"Polls a URL you control on a schedule — your service returns JSON items and Utopia keeps them in sync.",
@@ -541,6 +546,10 @@ export const en = {
azAccountField: "Storage account name",
azKeyField: "Account key",
gcsKeyField: "Service account JSON (paste the whole file)",
+ davUrlField: "Server URL",
+ davPathField: "Folder (optional — defaults to the root)",
+ davUserField: "Username",
+ davPassField: "Password",
tokenField: "GitHub token (optional, never shown again)",
includePullRequests: "Treat pull requests as tickets too",
interval: "Sync schedule",
diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts
index 9bacd6a8..8cd9bb05 100644
--- a/web/src/i18n/zh.ts
+++ b/web/src/i18n/zh.ts
@@ -428,6 +428,7 @@ export const zh: Strings = {
s3: "S3 / MinIO",
azure_blob: "Azure Blob",
gcs: "Google Cloud Storage",
+ webdav: "WebDAV",
},
sourceKindHints: {
folder:
@@ -451,6 +452,9 @@ export const zh: Strings = {
gcs:
"从 Google Cloud Storage 桶里读文档。服务账号 JSON 整份贴进来——" +
"服务器上没有那个文件可以指。",
+ webdav:
+ "从 WebDAV 网盘读文档——Nextcloud、ownCloud、群晖,以及一切说这套协议的。" +
+ "逐层走目录,每个文件成为一篇文档,日期取它最后一次修改的时刻。",
api: "外部系统把 JSON 文档推送到这里,用这个来源自己的令牌认证。",
custom:
"按计划轮询一个你控制的 URL——你的服务返回 JSON 条目,Utopia 保持同步。",
@@ -505,6 +509,10 @@ export const zh: Strings = {
azAccountField: "存储账号名",
azKeyField: "账号密钥",
gcsKeyField: "服务账号 JSON(整个文件贴进来)",
+ davUrlField: "服务器地址",
+ davPathField: "目录(可选——默认从根开始)",
+ davUserField: "用户名",
+ davPassField: "密码",
tokenField: "GitHub 令牌(可选,不再显示)",
includePullRequests: "把 PR 也当工单收进来",
interval: "同步计划",
diff --git a/web/src/pages/Library.tsx b/web/src/pages/Library.tsx
index f19e9620..3e2cbc35 100644
--- a/web/src/pages/Library.tsx
+++ b/web/src/pages/Library.tsx
@@ -1273,6 +1273,7 @@ function SourceModal({
| "s3"
| "azure_blob"
| "gcs"
+ | "webdav"
>("folder");
const [name, setName] = useState("");
const [icon, setIcon] = useState<string | null>(null);
@@ -1292,6 +1293,10 @@ function SourceModal({
const [azAccount, setAzAccount] = useState("");
const [azKey, setAzKey] = useState("");
const [gcsKey, setGcsKey] = useState("");
+ const [davUrl, setDavUrl] = useState("");
+ const [davPath, setDavPath] = useState("");
+ const [davUser, setDavUser] = useState("");
+ const [davPass, setDavPass] = useState("");
// PR 在 GitHub 的模型里也是工单。默认不收——问「工单」要的是工单;
// 但有些仓库的决策记录实际写在 PR 描述里,所以给个开关
const [includePrs, setIncludePrs] = useState(false);
@@ -1308,7 +1313,8 @@ function SourceModal({
kind === "jira_issues" ||
kind === "s3" ||
kind === "azure_blob" ||
- kind === "gcs";
+ kind === "gcs" ||
+ kind === "webdav";
const create = useMutation({
mutationFn: () => {
@@ -1361,7 +1367,14 @@ function SourceModal({
? { service_account_key: gcsKey.trim() }
: {}),
}
- : {};
+ : kind === "webdav"
+ ? {
+ base_url: davUrl.trim(),
+ ...(davPath.trim() ? { path: davPath.trim() } : {}),
+ ...(davUser.trim() ? { username: davUser.trim() } : {}),
+ ...(davPass ? { password: davPass } : {}),
+ }
+ : {};
return api.createSource(kbId, {
kind,
name: name.trim(),
@@ -1383,7 +1396,9 @@ function SourceModal({
? feedUrl.trim()
: kind === "custom"
? endpoint.trim()
- : kind === "s3" || kind === "azure_blob" || kind === "gcs"
+ : kind === "webdav"
+ ? davUrl.trim()
+ : kind === "s3" || kind === "azure_blob" || kind === "gcs"
? s3Bucket.trim()
: true);
@@ -1424,6 +1439,7 @@ function SourceModal({
"s3",
"azure_blob",
"gcs",
+ "webdav",
"api",
"custom",
] as const
@@ -1659,6 +1675,45 @@ function SourceModal({
)}
</>
)}
+ {kind === "webdav" && (
+ <>
+ {field(
+ S.library.davUrlField,
+ <input
+ className="input-dark w-full px-3 py-2 text-sm font-mono"
+ placeholder="https://cloud.example.com/remote.php/dav/files/alice"
+ value={davUrl}
+ onChange={(e) => setDavUrl(e.target.value)}
+ />,
+ )}
+ {field(
+ S.library.davPathField,
+ <input
+ className="input-dark w-full px-3 py-2 text-sm font-mono"
+ placeholder="/Documents"
+ value={davPath}
+ onChange={(e) => setDavPath(e.target.value)}
+ />,
+ )}
+ {field(
+ S.library.davUserField,
+ <input
+ className="input-dark w-full px-3 py-2 text-sm font-mono"
+ value={davUser}
+ onChange={(e) => setDavUser(e.target.value)}
+ />,
+ )}
+ {field(
+ S.library.davPassField,
+ <input
+ className="input-dark w-full px-3 py-2 text-sm font-mono"
+ type="password"
+ value={davPass}
+ onChange={(e) => setDavPass(e.target.value)}
+ />,
+ )}
+ </>
+ )}
{kind === "github_issues" && (
<>
{field(
diff --git a/web/src/pages/SourcesRail.tsx b/web/src/pages/SourcesRail.tsx
index de4bc579..64f250fe 100644
--- a/web/src/pages/SourcesRail.tsx
+++ b/web/src/pages/SourcesRail.tsx
@@ -70,6 +70,7 @@ export const KIND_ICON = {
s3: HardDrive,
azure_blob: Cloud,
gcs: Cloud,
+ webdav: FolderOpen,
memory: Brain,
upload: Upload,
} as const;
@@ -84,6 +85,7 @@ export const SYNCING_KINDS = new Set([
"s3",
"azure_blob",
"gcs",
+ "webdav",
]);
export const SYNC_DOT: Record<SourceView["last_sync_status"], string> = {