Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Preserve empty numeric sync settings until corrected https://github.com/siyuan-note/siyuan/issues/20421

Daniel1109d4f79d91
diff --git a/app/src/config/tabs/syncUi.test.ts b/app/src/config/tabs/syncUi.test.ts
index 7489dd8ee7..e89f2005b7 100644
--- a/app/src/config/tabs/syncUi.test.ts
+++ b/app/src/config/tabs/syncUi.test.ts
@@ -16,6 +16,7 @@ const setup = (initial: {endpoint?: string, bucket?: string} = {}) => {
Object.assign(s3, initial);
const inputs = Object.fromEntries(Object.keys(s3).map((key) => [key, {
value: "",
+ focus: () => {},
}]));
const messages: string[] = [];
const events: Record<string, (event: unknown) => void> = {};
@@ -59,6 +60,28 @@ const setup = (initial: {endpoint?: string, bucket?: string} = {}) => {
const settle = () => new Promise<void>((resolve) => setImmediate(resolve));
+for (const key of ["timeout", "concurrentReqs"] as const) {
+ test(`empty S3 ${key} preserves the input and configuration until corrected`, async () => {
+ const ui = setup();
+ ui.fill();
+ await settle();
+ const saved = {...ui.requests[0].data.s3};
+ ui.inputs[key].value = "";
+ ui.change();
+ ui.requests[0].resolve({code: 0, data: {s3: saved}});
+ await settle();
+ assert.equal(ui.requests.length, 1);
+ assert.equal(ui.inputs[key].value, "");
+ assert.equal(ui.sync.s3[key], saved[key]);
+ assert.deepEqual(ui.messages, ["Input can not be empty"]);
+ ui.inputs[key].value = "7";
+ ui.change();
+ await settle();
+ assert.equal(ui.requests.length, 2);
+ assert.equal(ui.requests[1].data.s3[key], 7);
+ });
+}
+
test("S3 bucket endpoint warning appears for saved configurations and follows edits without blocking saves", async () => {
const ui = setup({endpoint: "https://my.bucket.s3.example.com", bucket: "my.bucket"});
assert.equal(ui.warningHidden(), false);
diff --git a/app/src/config/tabs/syncUi.ts b/app/src/config/tabs/syncUi.ts
index a4f3b6dd91..c84ade144e 100644
--- a/app/src/config/tabs/syncUi.ts
+++ b/app/src/config/tabs/syncUi.ts
@@ -420,7 +420,19 @@ const saveSyncProviderConfigValues = (configElement: Element) => {
if (!isThirdPartySyncProviderDef(def)) {
return;
}
- const data = readProviderConfigFields(configElement, def.getConfig());
+ const template = def.getConfig();
+ for (const key of ["timeout", "concurrentReqs"] as const) {
+ if (typeof template[key] !== "number") {
+ continue;
+ }
+ const input = configElement.querySelector<HTMLInputElement>(`#${key}`);
+ if (input && !input.value.trim()) {
+ showMessage(window.siyuan.languages._kernel[142]);
+ input.focus();
+ return;
+ }
+ }
+ const data = readProviderConfigFields(configElement, template);
const configKey = def.configKey;
if (configKey === "s3") {
for (const key of ["endpoint", "accessKey", "secretKey", "bucket", "region"]) {