Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(config): CloudDrive2 配置里关着的挂载点通知也写全五个字段

longmeidao8f67084b91c7
diff --git a/frontend/src/react/settings/push-discovery-settings.tsx b/frontend/src/react/settings/push-discovery-settings.tsx
index d9af10b03..efeb6595e 100644
--- a/frontend/src/react/settings/push-discovery-settings.tsx
+++ b/frontend/src/react/settings/push-discovery-settings.tsx
@@ -114,8 +114,10 @@ export function PushDiscoveryForm({ initial, receipt }: {
<Stack divided>
<div className="flex flex-col gap-3">
<FieldLabel>CloudDrive2 配置内容</FieldLabel>
- <Help>在 CloudDrive2 的「系统设置 → 通知设置」里,复制这段配置贴进「配置内容」再保存。
- 地址、端点和密钥都已经填好了;换过密钥之后要重新贴一次。</Help>
+ <Help>在 CloudDrive2 的「设置 → Webhooks」里添加一条,把这段配置贴进去保存。
+ 地址、端点和密钥都已经填好了;换过密钥之后要重新贴一次。
+ Windows 桌面版的编辑框会把换行存坏,列表里标「无效」:那就把这段存成 .toml
+ 文件,放进 %LOCALAPPDATA%\CloudDrive.WinUI\webhooks\ 目录。</Help>
{live.config_toml ? (
<>
<div>
diff --git a/src/peach/push_discovery.py b/src/peach/push_discovery.py
index eac49ef0a..1a66ac32f 100644
--- a/src/peach/push_discovery.py
+++ b/src/peach/push_discovery.py
@@ -152,9 +152,12 @@ def parse_notification(body) -> list[str]:
return found
-#: CloudDrive2「通知设置」那个「配置内容」框里的整段 TOML。形状照它自带的默认模板,
+#: CloudDrive2「设置 → Webhooks」里一条 webhook 的整段 TOML。形状照它自带的默认模板,
#: 三处按本机填:地址、端点路径、共享密钥。`{base_url}`、`{action}` 这些花括号是
#: CloudDrive2 自己的占位符,Python 这边不碰,所以模板用 `%s` 代入。
+#:
+#: 两个 watcher 在它那边是同一个结构(`WebHookConfigItem`,5 个字段),五个字段一个
+#: 都不能省:关掉的那个只写 `enabled = false` 的话,整份配置在它的列表里标「无效」。
_CLOUDDRIVE_CONFIG = """[global_params]
base_url = "%s"
enabled = true
@@ -184,7 +187,12 @@ body = '''
%s = "%s"
[mount_point_watcher]
+url = "{base_url}%s"
+method = "POST"
enabled = false
+body = '{"data": []}'
+
+[mount_point_watcher.headers]
"""
@@ -201,7 +209,7 @@ def clouddrive_config(origin: str, secret: str) -> str:
origin, secret = str(origin or "").strip().rstrip("/"), str(secret or "").strip()
if not origin or not secret:
return ""
- return _CLOUDDRIVE_CONFIG % (origin, WEBHOOK_PATH, SECRET_HEADER, secret)
+ return _CLOUDDRIVE_CONFIG % (origin, WEBHOOK_PATH, SECRET_HEADER, secret, WEBHOOK_PATH)
def normalise_prefix(raw: str) -> str:
diff --git a/tests/test_push_discovery.py b/tests/test_push_discovery.py
index c95be4081..1abd2c425 100644
--- a/tests/test_push_discovery.py
+++ b/tests/test_push_discovery.py
@@ -104,6 +104,10 @@ class CloudDriveConfigTests(unittest.TestCase):
self.assertEqual(watcher["headers"][push.SECRET_HEADER], "s3cret-token")
# 挂载点通知一条路径也给不出,收下来只是空转一次队列。
self.assertIs(config["mount_point_watcher"]["enabled"], False)
+ # 两个 watcher 在 CloudDrive2 那边是同一个 5 字段结构,关着的那个也得写全:
+ # 只写 `enabled = false` 时整份配置在它的 Webhooks 列表里标「无效」。
+ for name in ("file_system_watcher", "mount_point_watcher"):
+ self.assertEqual(set(config[name]), {"url", "method", "enabled", "headers", "body"}, name)
# 默认模板里那行 `authorization = "basic usernamepassword"` 不能留:它是示例值,
# 发出来只会在 Peach 的访问日志里留一串假凭据。
self.assertNotIn("authorization", config["global_params"]["default_headers"])
diff --git a/web/dist/peach-react.js b/web/dist/peach-react.js
index 6ae6b6a4f..76ec93fa4 100644
--- a/web/dist/peach-react.js
+++ b/web/dist/peach-react.js
@@ -32950,7 +32950,7 @@ function $D({ initial: e, receipt: t }) {
className: "flex flex-col gap-3",
children: [
/* @__PURE__ */ (0, w.jsx)(RS, { children: "CloudDrive2 配置内容" }),
- /* @__PURE__ */ (0, w.jsx)(IS, { children: "在 CloudDrive2 的「系统设置 → 通知设置」里,复制这段配置贴进「配置内容」再保存。 地址、端点和密钥都已经填好了;换过密钥之后要重新贴一次。" }),
+ /* @__PURE__ */ (0, w.jsx)(IS, { children: "在 CloudDrive2 的「设置 → Webhooks」里添加一条,把这段配置贴进去保存。 地址、端点和密钥都已经填好了;换过密钥之后要重新贴一次。 Windows 桌面版的编辑框会把换行存坏,列表里标「无效」:那就把这段存成 .toml 文件,放进 %LOCALAPPDATA%\\CloudDrive.WinUI\\webhooks\\ 目录。" }),
d.config_toml ? /* @__PURE__ */ (0, w.jsxs)(w.Fragment, { children: [/* @__PURE__ */ (0, w.jsx)("div", { children: /* @__PURE__ */ (0, w.jsx)(X, {
size: "small",
onClick: () => {