Skip to content

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

:bug: fix encrypted-notebook loading button stuck on wrong password #18034

Daniel764254c2fe96
diff --git a/app/src/config/tabs/accessTab.ts b/app/src/config/tabs/accessTab.ts
index 27531e68d6..78ad6b1ffe 100644
--- a/app/src/config/tabs/accessTab.ts
+++ b/app/src/config/tabs/accessTab.ts
@@ -1,5 +1,5 @@
import type {SettingTabBuilder} from "../setting/builder";
-import {fetchPost} from "../../util/fetch";
+import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {Dialog} from "../../dialog";
import {Constants} from "../../constants";
import {isBrowser, isMobile} from "../../util/functions";
@@ -411,7 +411,7 @@ const openEnableEncryptedDialog = (onSuccess: () => void, onCancel: () => void)
dialog.destroy();
onCancel();
});
- confirmBtn.addEventListener("click", () => {
+ confirmBtn.addEventListener("click", async () => {
const pwd1 = (inputs[0] as HTMLInputElement).value;
const pwd2 = (inputs[1] as HTMLInputElement).value;
if (!pwd1) {
@@ -426,14 +426,16 @@ const openEnableEncryptedDialog = (onSuccess: () => void, onCancel: () => void)
const originalText = confirmBtn.textContent;
confirmBtn.setAttribute("disabled", "disabled");
confirmBtn.textContent = window.siyuan.languages.loading;
- fetchPost("/api/notebook/enableEncryptedNotebooks", {password: pwd1}, () => {
+ const response = await fetchSyncPost("/api/notebook/enableEncryptedNotebooks", {password: pwd1});
+ if (response.code === 0) {
showMessage(window.siyuan.languages.encryptedNotebookEnabled);
dialog.destroy();
onSuccess();
- }, undefined, () => {
+ } else {
+ // fetchSyncPost 已通过 processMessage 弹出错误提示,这里只需恢复按钮
confirmBtn.removeAttribute("disabled");
confirmBtn.textContent = originalText;
- });
+ }
});
};
@@ -458,7 +460,7 @@ const openChangeMasterPasswordDialog = () => {
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
});
- btnsElement[1].addEventListener("click", () => {
+ btnsElement[1].addEventListener("click", async () => {
const oldPwd = (inputs[0] as HTMLInputElement).value;
const newPwd = (inputs[1] as HTMLInputElement).value;
const confirmPwd = (inputs[2] as HTMLInputElement).value;
@@ -474,15 +476,17 @@ const openChangeMasterPasswordDialog = () => {
const originalText = confirmBtn.textContent;
confirmBtn.setAttribute("disabled", "disabled");
confirmBtn.textContent = window.siyuan.languages.loading;
- fetchPost("/api/notebook/changeMasterPassword", {
+ const response = await fetchSyncPost("/api/notebook/changeMasterPassword", {
oldPassword: oldPwd,
newPassword: newPwd
- }, () => {
+ });
+ if (response.code === 0) {
showMessage(window.siyuan.languages.changeMasterPassword);
dialog.destroy();
- }, undefined, () => {
+ } else {
+ // fetchSyncPost 已通过 processMessage 弹出错误提示,这里只需恢复按钮
confirmBtn.removeAttribute("disabled");
confirmBtn.textContent = originalText;
- });
+ }
});
};
diff --git a/app/src/util/mount.ts b/app/src/util/mount.ts
index cc72d9fd4d..656648d26d 100644
--- a/app/src/util/mount.ts
+++ b/app/src/util/mount.ts
@@ -1,7 +1,7 @@
import {Constants} from "../constants";
import {showMessage} from "../dialog/message";
import {isMobile} from "./functions";
-import {fetchPost} from "./fetch";
+import {fetchPost, fetchSyncPost} from "./fetch";
import {Dialog} from "../dialog";
import {getOpenNotebookCount} from "./pathName";
import {replaceFileName, validateName} from "../editor/rename";
@@ -205,7 +205,7 @@ export const openEncryptedNotebook = (app: App, notebookId: string, name: string
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
});
- btnsElement[1].addEventListener("click", () => {
+ btnsElement[1].addEventListener("click", async () => {
const password = inputElement.value;
if (!password) {
return false;
@@ -215,18 +215,19 @@ export const openEncryptedNotebook = (app: App, notebookId: string, name: string
unlockBtn.setAttribute("disabled", "disabled");
unlockBtn.textContent = window.siyuan.languages.loading;
// 先解锁(派生 KEK + 解 DEK + 打开加密 db,Argon2id 约耗时 1 秒),成功后再挂载
- fetchPost("/api/notebook/unlockBox", {
+ const response = await fetchSyncPost("/api/notebook/unlockBox", {
notebook: notebookId,
password
- }, () => {
+ });
+ if (response.code === 0) {
fetchPost("/api/notebook/openNotebook", {
notebook: notebookId
});
dialog.destroy();
- }, undefined, (err) => {
+ } else {
+ // fetchSyncPost 已通过 processMessage 弹出错误提示,这里只需恢复按钮
unlockBtn.removeAttribute("disabled");
unlockBtn.textContent = originalText;
- showMessage(err.msg || window.siyuan.languages.incorrectMasterPassword);
- });
+ }
});
};