An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Encrypted notebook: roll back disable toggle when backend rejects it
Daniele6e7a1079ee4
diff --git a/app/src/config/tabs/accessTab.ts b/app/src/config/tabs/accessTab.tsindex 1e7ba8e1d5..d1b62c88ec 100644--- a/app/src/config/tabs/accessTab.ts+++ b/app/src/config/tabs/accessTab.ts@@ -510,8 +510,17 @@ const mountEncryptedNotebook = (root: HTMLElement) => {if (response.data.count > 0) {showMessage(window.siyuan.languages.encryptedNotebookDisableTip.replace("${x}", response.data.count), 4000);switchElement.checked = true;+ } else if (response.data.hasHistoryDependency) {+ // 已删除加密笔记本的历史仍依赖当前密钥备份,禁用会让其永久锁死(详见设计 §19)+ showMessage(window.siyuan.languages["_kernel"]["323"], 6000, "error");+ switchElement.checked = true;} else {- fetchPost("/api/notebook/disableEncryptedNotebooks", {}, () => {+ // 用 sync 调用以便后端因任何原因拒绝时回滚开关,避免 UI 与后端状态不一致+ fetchSyncPost("/api/notebook/disableEncryptedNotebooks", {}).then((res: IWebSocketData) => {+ if (res.code === -1) {+ switchElement.checked = true; // processMessage 已弹出错误,这里只回滚开关+ return;+ }showMessage(window.siyuan.languages.encryptedNotebookDisabled);refresh();});diff --git a/kernel/api/notebook.go b/kernel/api/notebook.goindex ab7bc55c22..8bd4b392d1 100644--- a/kernel/api/notebook.go+++ b/kernel/api/notebook.go@@ -753,6 +753,9 @@ func getEncryptedNotebookStatus(c *gin.Context) {enabled := model.NotebookCryptoEnabled()model.NotebookCryptoMuUnlock()pendingMigration, migrationBoxes := model.MasterPasswordMigrationStatus()+ // 历史目录中是否存在已删除加密笔记本的历史快照:其恢复依赖当前密钥备份,+ // 存在时前端禁用入口应拦截(与 DisableEncryptedNotebook 的后端检查对齐)+ hasHistoryDependency := model.HasEncryptedNotebookHistory()boxes := make([]map[string]any, 0, len(boxIDs))for _, id := range boxIDs {@@ -769,11 +772,12 @@ func getEncryptedNotebookStatus(c *gin.Context) {}ret.Data = map[string]any{- "enabled": enabled,- "count": len(boxIDs),- "boxes": boxes,- "migrationPending": pendingMigration,- "migrationBoxes": migrationBoxes,+ "enabled": enabled,+ "count": len(boxIDs),+ "boxes": boxes,+ "migrationPending": pendingMigration,+ "migrationBoxes": migrationBoxes,+ "hasHistoryDependency": hasHistoryDependency,}}diff --git a/kernel/model/crypto.go b/kernel/model/crypto.goindex c8ee509708..e1bca85d2f 100644--- a/kernel/model/crypto.go+++ b/kernel/model/crypto.go@@ -511,7 +511,7 @@ func hasEncryptedNotebook() bool {return len(ListAllEncryptedBoxIDs()) > 0}-// hasEncryptedNotebookHistory 检查历史目录中是否存在加密笔记本的历史快照。+// HasEncryptedNotebookHistory 检查历史目录中是否存在加密笔记本的历史快照。// 笔记本删除后其 box 目录(含 .siyuan/conf.json 和 notebook-crypt-backup.json)会被// 原样密文备份到历史目录(RemoveBox 的 filelock.Copy),但此时 IsEncryptedBox 已返回 false// (box 目录已删)。因此 DisableEncryptedNotebook 不能只靠 ListAllEncryptedBoxIDs 判定——@@ -521,7 +521,7 @@ func hasEncryptedNotebook() bool {// 判定信号:历史条目 <HistoryDir>/<ts>-<op>/<boxID>/.siyuan/ 下存在// notebook-crypt-backup.json(专为 box 删除后的恢复设计),或 conf.json 标记 Encrypted=true。// boxID 用 ast.IsNodeIDPattern 校验,避免误判 assets/storage 等非 box 目录。-func hasEncryptedNotebookHistory() bool {+func HasEncryptedNotebookHistory() bool {entries, err := os.ReadDir(util.HistoryDir)if err != nil {return false // 历史目录不存在或不可读 → 无依赖@@ -679,7 +679,7 @@ func DisableEncryptedNotebook() error {}// 检查历史目录中是否存在已删除加密笔记本的历史快照:其恢复仍依赖当前 MasterSalt/KEKVerifier,// 删除备份前必须先清除这些历史(详见设计 §19)- if hasEncryptedNotebookHistory() {+ if HasEncryptedNotebookHistory() {return errors.New(Conf.Language(323))}