Skip to content

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

:sparkles: encrypted-notebook InBox: outline + breadcrumb #18034

Daniel9266bb0ec8b7
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index 3950100e99..34e0e1957e 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -641,10 +641,14 @@ export const updateOutline = (models: IModels, protyle: IProtyle, reload = false
return;
}
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: blockId,
preview: !protyle.preview.element.classList.contains("fn__none")
- }, response => {
+ };
+ if (protyle && isEncryptedBox(protyle.notebookId)) {
+ outlineParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
if (!reload && (!isCurrentEditor(blockId) || item.blockId === blockId) &&
item.isPreview !== protyle.preview.element.classList.contains("fn__none")) {
return;
diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.ts
index ba2cff077a..c640f80f48 100644
--- a/app/src/layout/dock/Outline.ts
+++ b/app/src/layout/dock/Outline.ts
@@ -23,6 +23,7 @@ import {App} from "../../index";
import {checkFold} from "../../util/noRelyPCFunction";
import {transaction, turnsIntoTransaction} from "../../protyle/wysiwyg/transaction";
import {goHome} from "../../protyle/wysiwyg/commonHotkey";
+import {isEncryptedBox} from "../../util/pathName";
import {Editor} from "../../editor";
import {mathRender} from "../../protyle/render/mathRender";
import {genEmptyElement} from "../../block/util";
@@ -288,10 +289,22 @@ export class Outline extends Model {
});
this.bindSort();
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: this.blockId,
preview: this.isPreview
- }, response => {
+ };
+ // 解析当前大纲面板所属 box:按 blockId 在已打开的编辑器里查找
+ let notebookId: string;
+ getAllModels().editor.some(item => {
+ if (item.editor.protyle.block.rootID === this.blockId) {
+ notebookId = item.editor.protyle.notebookId;
+ return true;
+ }
+ });
+ if (isEncryptedBox(notebookId)) {
+ outlineParam.notebook = notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
this.update(response);
if (this.blockId) {
this.updateDocTitle((options.tab.model as Editor)?.editor?.protyle?.background?.ial, response.data?.length || 0);
@@ -549,10 +562,22 @@ export class Outline extends Model {
});
}
if (needReload) {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: this.blockId,
preview: this.isPreview
- }, response => {
+ };
+ // 解析当前大纲面板所属 box:按 blockId 在已打开的编辑器里查找
+ let notebookId: string;
+ getAllModels().editor.some(item => {
+ if (item.editor.protyle.block.rootID === this.blockId) {
+ notebookId = item.editor.protyle.notebookId;
+ return true;
+ }
+ });
+ if (isEncryptedBox(notebookId)) {
+ outlineParam.notebook = notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
// 文档切换后不再更新原有推送 https://github.com/siyuan-note/siyuan/issues/13409
if (data.data.rootID !== this.blockId) {
return;
@@ -592,10 +617,22 @@ export class Outline extends Model {
if (previousElement) {
this.setCurrentById(previousElement.getAttribute("data-node-id"));
} else {
- fetchPost("/api/block/getBlockBreadcrumb", {
+ const breadcrumbParam: IObject = {
id: nodeElement.getAttribute("data-node-id"),
excludeTypes: []
- }, (response) => {
+ };
+ // 解析当前大纲面板所属 box:按 blockId 在已打开的编辑器里查找
+ let notebookId: string;
+ getAllModels().editor.some(editorItem => {
+ if (editorItem.editor.protyle.block.rootID === this.blockId) {
+ notebookId = editorItem.editor.protyle.notebookId;
+ return true;
+ }
+ });
+ if (isEncryptedBox(notebookId)) {
+ breadcrumbParam.notebook = notebookId;
+ }
+ fetchPost("/api/block/getBlockBreadcrumb", breadcrumbParam, (response) => {
response.data.reverse().find((item: IBreadcrumb) => {
if (item.type === "NodeHeading") {
this.setCurrentById(item.id);
diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.ts
index 040d02f15d..8a84cbc974 100644
--- a/app/src/mobile/dock/MobileOutline.ts
+++ b/app/src/mobile/dock/MobileOutline.ts
@@ -14,6 +14,7 @@ import {focusBlock, focusByWbr} from "../../protyle/util/selection";
import {openMobileFileById} from "../editor";
import {Model} from "../../layout/Model";
import {genUUID} from "../../util/genID";
+import {isEncryptedBox} from "../../util/pathName";
export class MobileOutline extends Model {
public tree: Tree;
@@ -183,10 +184,15 @@ export class MobileOutline extends Model {
}
});
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: this.blockId,
preview: this.isPreview
- }, response => {
+ };
+ const mobileProtyle = window.siyuan.mobile.editor?.protyle;
+ if (mobileProtyle && mobileProtyle.block.rootID === this.blockId && isEncryptedBox(mobileProtyle.notebookId)) {
+ outlineParam.notebook = mobileProtyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
this.update(response);
});
}
@@ -219,10 +225,15 @@ export class MobileOutline extends Model {
if (previousElement) {
this.setCurrentById(previousElement.getAttribute("data-node-id"));
} else {
- fetchPost("/api/block/getBlockBreadcrumb", {
+ const breadcrumbParam: IObject = {
id: nodeElement.getAttribute("data-node-id"),
excludeTypes: []
- }, (response) => {
+ };
+ const mobileProtyle = window.siyuan.mobile.editor?.protyle;
+ if (mobileProtyle && mobileProtyle.block.rootID === this.blockId && isEncryptedBox(mobileProtyle.notebookId)) {
+ breadcrumbParam.notebook = mobileProtyle.notebookId;
+ }
+ fetchPost("/api/block/getBlockBreadcrumb", breadcrumbParam, (response) => {
response.data.reverse().find((item: IBreadcrumb) => {
if (item.type === "NodeHeading") {
this.setCurrentById(item.id);
@@ -538,10 +549,15 @@ export class MobileOutline extends Model {
});
}
if (needReload) {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: this.blockId,
preview: this.isPreview
- }, response => {
+ };
+ const mobileProtyle = window.siyuan.mobile.editor?.protyle;
+ if (mobileProtyle && mobileProtyle.block.rootID === this.blockId && isEncryptedBox(mobileProtyle.notebookId)) {
+ outlineParam.notebook = mobileProtyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
// 文档切换后不再更新原有推送 https://github.com/siyuan-note/siyuan/issues/13409
if (data.data.rootID !== this.blockId) {
return;
diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts
index 795bb3e3ad..dd9592e337 100644
--- a/app/src/mobile/util/initFramework.ts
+++ b/app/src/mobile/util/initFramework.ts
@@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch";
import {setInlineStyle} from "../../util/assets";
import {renderSnippet} from "../../config/util/snippets";
import {setEmpty} from "./setEmpty";
-import {getOpenNotebookCount, parseUriInfo} from "../../util/pathName";
+import {getOpenNotebookCount, isEncryptedBox, parseUriInfo} from "../../util/pathName";
import {popMenu} from "../menu";
import {MobileFiles} from "../dock/MobileFiles";
import {MobileOutline} from "../dock/MobileOutline";
@@ -102,10 +102,14 @@ export const initFramework = (app: App, isStart: boolean) => {
isPreview: window.siyuan.mobile.editor ? !window.siyuan.mobile.editor.protyle.preview.element.classList.contains("fn__none") : false
});
} else {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: window.siyuan.mobile.editor.protyle.block.rootID,
preview: window.siyuan.mobile.editor.protyle.preview.element.classList.contains("fn__none")
- }, response => {
+ };
+ if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {
+ outlineParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
window.siyuan.mobile.docks.outline.update(response);
});
}
@@ -154,10 +158,14 @@ export const initFramework = (app: App, isStart: boolean) => {
sidebarElement.style.transform = "translateX(0px)";
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
if (type === "sidebar-outline-tab") {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: window.siyuan.mobile.editor.protyle.block.rootID,
preview: window.siyuan.mobile.editor.protyle.preview.element.classList.contains("fn__none")
- }, response => {
+ };
+ if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {
+ outlineParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
window.siyuan.mobile.docks.outline.update(response);
});
} else if (type === "sidebar-backlink-tab") {
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index 84690d28a7..362456876e 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -225,7 +225,11 @@ ${padHTML}
return;
}
const id = blockElement.getAttribute("data-node-id");
- fetchPost("/api/block/getBlockBreadcrumb", {id, excludeTypes: []}, (response) => {
+ const breadcrumbParam: IObject = {id, excludeTypes: []};
+ if (isEncryptedBox(protyle.notebookId)) {
+ breadcrumbParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getBlockBreadcrumb", breadcrumbParam, (response) => {
response.data.forEach((item: IBreadcrumb) => {
let isCurrent = false;
if (!protyle.block.showAll && item.id === protyle.block.parentID) {
@@ -629,7 +633,11 @@ ${padHTML}
// 闪卡面包屑不能显示答案
excludeTypes.push("NodeTextMark-mark");
}
- fetchPost("/api/block/getBlockBreadcrumb", {id, excludeTypes}, (response) => {
+ const breadcrumbParam: IObject = {id, excludeTypes};
+ if (isEncryptedBox(protyle.notebookId)) {
+ breadcrumbParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getBlockBreadcrumb", breadcrumbParam, (response) => {
let html = "";
response.data.forEach((item: IBreadcrumb, index: number) => {
let isCurrent = false;
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index f0c998010e..0b64028933 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -141,10 +141,14 @@ export class Protyle {
/// #if !MOBILE
getAllModels().outline.forEach(item => {
if (item.blockId === data.data) {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: item.blockId,
preview: item.isPreview
- }, response => {
+ };
+ if (isEncryptedBox(this.protyle.notebookId)) {
+ outlineParam.notebook = this.protyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
item.update(response);
});
}
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 099972d51b..cd7e2fe819 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -70,6 +70,7 @@ import {popSearch} from "../../mobile/menu/search";
import {copyPlainText, encodeBase64, isInIOS, isMac, isOnlyMeta, readClipboard} from "../util/compatibility";
import {MenuItem} from "../../menus/Menu";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
+import {isEncryptedBox} from "../../util/pathName";
import {onGet} from "../util/onGet";
import {clearTableCell, getTableRangeHTML, isIncludeCell, setTableAlign, updateTableTitle} from "../util/table";
import {countBlockWord, countSelectWord} from "../../layout/status";
@@ -3226,10 +3227,14 @@ export class WYSIWYG {
/// #if !MOBILE
getAllModels().outline.forEach(item => {
if (item.blockId === protyle.block.rootID) {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: item.blockId,
preview: item.isPreview
- }, response => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ outlineParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
item.update(response);
});
}
diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.ts
index 1eab8f1609..04e5399d8c 100644
--- a/app/src/util/reloadSync.ts
+++ b/app/src/util/reloadSync.ts
@@ -4,7 +4,7 @@ import {hideElements} from "../protyle/ui/hideElements";
import {setEmpty} from "../mobile/util/setEmpty";
import {fetchPost} from "./fetch";
import {Constants} from "../constants";
-import {getDocDisplayName, setNoteBook} from "./pathName";
+import {getDocDisplayName, isEncryptedBox, setNoteBook} from "./pathName";
import {getAllModels} from "../layout/getAll";
import {setStorageVal} from "../protyle/util/compatibility";
import type {Tab} from "../layout/Tab";
@@ -89,10 +89,22 @@ export const reloadSync = (
if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) {
item.parent.parent.removeTab(item.parent.id, false, false);
} else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {
- fetchPost("/api/outline/getDocOutline", {
+ const outlineParam: IObject = {
id: item.blockId,
preview: item.isPreview
- }, response => {
+ };
+ // 解析大纲面板所属 box:按 blockId 在已打开的编辑器里查找
+ let notebookId: string;
+ allModels.editor.some(editorItem => {
+ if (editorItem.editor.protyle.block.rootID === item.blockId) {
+ notebookId = editorItem.editor.protyle.notebookId;
+ return true;
+ }
+ });
+ if (isEncryptedBox(notebookId)) {
+ outlineParam.notebook = notebookId;
+ }
+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {
item.update(response);
});
if (item.type === "local") {
diff --git a/kernel/api/block.go b/kernel/api/block.go
index 8856dc7eee..ac6c07e414 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -666,7 +666,13 @@ func getBlockBreadcrumb(c *gin.Context) {
}
}
- blockPath, err := model.BuildBlockBreadcrumb(id, excludeTypes)
+ var blockPath []*model.BlockPath
+ var err error
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ blockPath, err = model.BuildBlockBreadcrumbInBox(id, excludeTypes, notebook)
+ } else {
+ blockPath, err = model.BuildBlockBreadcrumb(id, excludeTypes)
+ }
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
diff --git a/kernel/api/outline.go b/kernel/api/outline.go
index 782801c2c4..a38def5735 100644
--- a/kernel/api/outline.go
+++ b/kernel/api/outline.go
@@ -49,7 +49,13 @@ func getDocOutline(c *gin.Context) {
return
}
- headings, err := model.Outline(rootID, preview)
+ var headings []*model.Path
+ var err error
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ headings, err = model.OutlineInBox(rootID, preview, notebook)
+ } else {
+ headings, err = model.Outline(rootID, preview)
+ }
if err != nil {
ret.Code = 1
ret.Msg = err.Error()
diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go
index d103c2c0d3..76df5a9f50 100644
--- a/kernel/model/blockinfo.go
+++ b/kernel/model/blockinfo.go
@@ -498,8 +498,13 @@ type BlockPath struct {
}
func BuildBlockBreadcrumb(id string, excludeTypes []string) (ret []*BlockPath, err error) {
+ return BuildBlockBreadcrumbInBox(id, excludeTypes, "")
+}
+
+// BuildBlockBreadcrumbInBox 与 BuildBlockBreadcrumb 一致,但按 boxID 路由 blocktree 查询到加密 db 或全局 db。
+func BuildBlockBreadcrumbInBox(id string, excludeTypes []string, boxID string) (ret []*BlockPath, err error) {
ret = []*BlockPath{}
- tree, err := LoadTreeByBlockID(id)
+ tree, err := loadTreeByBlockIDInBox(id, boxID)
if nil == tree {
err = nil
return
diff --git a/kernel/model/outline.go b/kernel/model/outline.go
index d7b47d1b2a..42eadb0c4b 100644
--- a/kernel/model/outline.go
+++ b/kernel/model/outline.go
@@ -208,10 +208,15 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
}
func Outline(rootID string, preview bool) (ret []*Path, err error) {
+ return OutlineInBox(rootID, preview, "")
+}
+
+// OutlineInBox 与 Outline 一致,但按 boxID 路由 blocktree 查询到加密 db 或全局 db。
+func OutlineInBox(rootID string, preview bool, boxID string) (ret []*Path, err error) {
FlushTxQueue()
ret = []*Path{}
- tree, _ := LoadTreeByBlockID(rootID)
+ tree, _ := loadTreeByBlockIDInBox(rootID, boxID)
if nil == tree {
return
}