Skip to content

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

:sparkles: encrypted-notebook InBox: docInfo + block hover/kramdown #18034

Daniel3ea6e0938186
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index a7b5f06fc4..0699b7283a 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -27,7 +27,7 @@ import {newDailyNote} from "../../util/mount";
import {hideElements} from "../../protyle/ui/hideElements";
import {fetchPost} from "../../util/fetch";
import {goBack, goForward} from "../../util/backForward";
-import {getDisplayName, getNotebookName} from "../../util/pathName";
+import {getDisplayName, getNotebookName, isEncryptedBox} from "../../util/pathName";
import {openFileById} from "../../editor/util";
import {getAllDocks, getAllModels, getAllTabs} from "../../layout/getAll";
import {focusBlock, focusByRange} from "../../protyle/util/selection";
@@ -652,9 +652,13 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
if (matchHotKey(window.siyuan.config.keymap.editor.general.rename.custom, event)) {
window.siyuan.menus.menu.remove();
if (isFile) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: liElements[0].getAttribute("data-node-id")
- }, (response) => {
+ };
+ if (isEncryptedBox(notebookId)) {
+ docInfoParam.notebook = notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
rename({
notebookId,
path: pathString,
diff --git a/app/src/editor/deleteFile.ts b/app/src/editor/deleteFile.ts
index be188dd2e3..17ab2d9d80 100644
--- a/app/src/editor/deleteFile.ts
+++ b/app/src/editor/deleteFile.ts
@@ -1,5 +1,5 @@
import {fetchPost} from "../util/fetch";
-import {getDisplayName, getNotebookName} from "../util/pathName";
+import {getDisplayName, getNotebookName, isEncryptedBox} from "../util/pathName";
import {confirmDialog} from "../dialog/confirmDialog";
import {hasTopClosestByTag} from "../protyle/util/hasClosest";
import {showMessage} from "../dialog/message";
@@ -14,9 +14,13 @@ export const deleteFile = (notebookId: string, pathString: string) => {
});
return;
}
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: getDisplayName(pathString, true, true)
- }, (response) => {
+ };
+ if (isEncryptedBox(notebookId)) {
+ docInfoParam.notebook = notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
const fileName = escapeHtml(response.data.name);
let tip = `${window.siyuan.languages.confirmDeleteTip.replace("${x}", fileName)}
<div class="fn__hr"></div>
diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts
index a64ac41fe3..c1f396e2ae 100644
--- a/app/src/menus/commonMenuItem.ts
+++ b/app/src/menus/commonMenuItem.ts
@@ -3,7 +3,7 @@ import {shell} from "electron";
/// #endif
import {confirmDialog} from "../dialog/confirmDialog";
import {getSearch, isMobile, isValidCustomAttrName} from "../util/functions";
-import {isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";
+import {isEncryptedBox, isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";
import {MenuItem} from "./Menu";
import {onExport, saveExport} from "../protyle/export";
import {exportMarkdownZip} from "../protyle/export/exportMd";
@@ -111,9 +111,13 @@ export const openWechatNotify = (nodeElement: Element) => {
};
export const openFileWechatNotify = (protyle: IProtyle) => {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
const reminder = response.data.ial[Constants.CUSTOM_REMINDER_WECHAT];
let reminderFormat = "";
if (reminder) {
@@ -981,9 +985,13 @@ export const renameMenu = (options: {
label: window.siyuan.languages.rename,
click: () => {
if (options.type === "file" && options.docId) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: options.docId
- }, (response) => {
+ };
+ if (isEncryptedBox(options.notebookId)) {
+ docInfoParam.notebook = options.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
rename({
...options,
name: response.data.ial.title,
diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts
index fc386a7918..d7abcdc574 100644
--- a/app/src/menus/navigation.ts
+++ b/app/src/menus/navigation.ts
@@ -4,7 +4,7 @@ import {FileFilter, ipcRenderer} from "electron";
import * as path from "path";
/// #endif
import {MenuItem} from "./Menu";
-import {getDisplayName, getNotebookName, getTopPaths, pathPosix, useShell} from "../util/pathName";
+import {getDisplayName, getNotebookName, getTopPaths, isEncryptedBox, pathPosix, useShell} from "../util/pathName";
import {showMessage} from "../dialog/message";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {onGetnotebookconf} from "./onGetnotebookconf";
@@ -524,9 +524,13 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
label: window.siyuan.languages.attr,
icon: "iconAttr",
click() {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id
- }, (response) => {
+ };
+ if (isEncryptedBox(notebookId)) {
+ docInfoParam.notebook = notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
openFileAttr(response.data.ial);
});
}
diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts
index 624a0d0f16..c9520661e2 100644
--- a/app/src/mobile/editor.ts
+++ b/app/src/mobile/editor.ts
@@ -55,7 +55,11 @@ export const openMobileFileById = (app: App, id: string, action: TProtyleAction[
}
}
- fetchPost("/api/block/getBlockInfo", {id}, (data) => {
+ const blockInfoParam: IObject = {id};
+ if (isEncryptedBox(window.siyuan.mobile.editor?.protyle?.notebookId)) {
+ blockInfoParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;
+ }
+ fetchPost("/api/block/getBlockInfo", blockInfoParam, (data) => {
if (data.code === 3) {
showMessage(data.msg);
return;
diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts
index 4b99cbd1c5..1a17b127b7 100644
--- a/app/src/mobile/util/MobileBackFoward.ts
+++ b/app/src/mobile/util/MobileBackFoward.ts
@@ -44,9 +44,13 @@ const focusStack = (backStack: IBackStack) => {
}
if (backStack.id !== protyle.block.rootID) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: backStack.id,
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
setTitle(response.data.name);
protyle.title.setTitle(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");
protyle.background.render(response.data.ial, protyle.block.rootID);
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index 362456876e..47d5f9a912 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -91,9 +91,13 @@ ${padHTML}
} else if (type === "doc") {
// 不使用 window.siyuan.shiftIsPressed ,否则窗口未激活时按 Shift 点击块标无法打开属性面板 https://github.com/siyuan-note/siyuan/issues/15075
if (event.shiftKey) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
openFileAttr(response.data.ial, "bookmark", protyle);
});
} else {
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index f3e3d11a19..4d6bcc7fa8 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -17,7 +17,7 @@ import * as dayjs from "dayjs";
/// #if !MOBILE
import {openFileById} from "../../editor/util";
/// #endif
-import {getDocDisplayName} from "../../util/pathName";
+import {getDocDisplayName, isEncryptedBox} from "../../util/pathName";
import {getContenteditableElement, getNoContainerElement} from "../wysiwyg/getBlock";
import {commonHotkey} from "../wysiwyg/commonHotkey";
import {nbsp2space} from "../util/normalizeText";
@@ -176,9 +176,13 @@ export class Title {
event.preventDefault();
event.stopPropagation();
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.attr.custom, event)) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
openFileAttr(response.data.ial, "bookmark", protyle);
});
event.preventDefault();
@@ -193,9 +197,13 @@ export class Title {
iconElement.addEventListener("click", (event) => {
// 不使用 window.siyuan.shiftIsPressed ,否则窗口未激活时按 Shift 点击块标无法打开属性面板 https://github.com/siyuan-note/siyuan/issues/15075
if (event.shiftKey) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
openFileAttr(response.data.ial, "bookmark", protyle);
});
} else {
@@ -307,9 +315,13 @@ export class Title {
this.element.querySelector(".protyle-attr").addEventListener("click", (event: MouseEvent & {
target: HTMLElement
}) => {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
commonClick(event, protyle, response.data.ial);
});
});
diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts
index 5e057517ff..6b8e01c1cd 100644
--- a/app/src/protyle/header/openTitleMenu.ts
+++ b/app/src/protyle/header/openTitleMenu.ts
@@ -12,7 +12,7 @@ import {openMobileFileById} from "../../mobile/editor";
import {Constants} from "../../constants";
import {openCardByData} from "../../card/openCard";
import {viewCards} from "../../card/viewCards";
-import {getDisplayName, getNotebookName, pathPosix, useShell} from "../../util/pathName";
+import {getDisplayName, getNotebookName, isEncryptedBox, pathPosix, useShell} from "../../util/pathName";
import {makeCard, quickMakeCard} from "../../card/makeCard";
import {emitOpenMenu} from "../../plugin/EventBus";
import * as dayjs from "dayjs";
@@ -35,9 +35,13 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: stri
window.siyuan.menus.menu.remove();
return;
}
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_TITLE);
const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index fc39237727..53639b97b4 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -104,9 +104,13 @@ export const onGet = (options: {
return;
}
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: options.protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(options.protyle.notebookId)) {
+ docInfoParam.notebook = options.protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
if (options.protyle.options.render.title) {
// 页签没有打开
options.protyle.title.render(options.protyle, response);
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 936767e269..52f0d1dafa 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -49,7 +49,7 @@ import {fontEvent} from "../toolbar/Font";
import {addSubList, listIndent, listOutdent, toggleTaskListItem} from "./list";
import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
import {cancelSB, insertEmptyBlock, jumpToParent} from "../../block/util";
-import {isLocalPath} from "../../util/pathName";
+import {isEncryptedBox, isLocalPath} from "../../util/pathName";
/// #if !MOBILE
import {openBy, openFileById} from "../../editor/util";
/// #endif
@@ -1209,9 +1209,13 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.rename.custom, event) && !protyle.disabled) {
if (selectText === "") {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
rename({
notebookId: protyle.notebookId,
path: protyle.path,
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 3632748988..558b3066f5 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -1151,9 +1151,13 @@ export const getArticle = (options: {
}
options.edit.protyle.scroll.lastScrollTop = 0;
addLoading(options.edit.protyle);
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: options.id,
- }, (response) => {
+ };
+ if (isEncryptedBox(options.edit.protyle.notebookId)) {
+ docInfoParam.notebook = options.edit.protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
if (articleId !== options.id) {
return;
}
diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.ts
index 0d070f8f02..547395f6f2 100644
--- a/app/src/util/backForward.ts
+++ b/app/src/util/backForward.ts
@@ -40,7 +40,11 @@ const focusStack = async (app: App, stack: IBackStack) => {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
if (wnd) {
- const info = await fetchSyncPost("/api/block/getBlockInfo", {id: stack.id});
+ const blockInfoParam: IObject = {id: stack.id};
+ if (isEncryptedBox(stack.protyle.notebookId)) {
+ blockInfoParam.notebook = stack.protyle.notebookId;
+ }
+ const info = await fetchSyncPost("/api/block/getBlockInfo", blockInfoParam);
if (info.code === 3) {
showMessage(info.msg);
return;
diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.ts
index 04e5399d8c..cf2a3ad32e 100644
--- a/app/src/util/reloadSync.ts
+++ b/app/src/util/reloadSync.ts
@@ -36,9 +36,13 @@ export const reloadSync = (
setEmpty(app);
} else {
window.siyuan.mobile.editor.reload(false, updateReadonly);
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: window.siyuan.mobile.editor.protyle.block.rootID
- }, (response) => {
+ };
+ if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {
+ docInfoParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
setTitle(response.data.name);
window.siyuan.mobile.editor.protyle.title.setTitle(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");
});
@@ -50,9 +54,13 @@ export const reloadSync = (
/// #else
const allModels = getAllModels();
const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: rootID
- }, (response) => {
+ };
+ if (protyle && isEncryptedBox(protyle.notebookId)) {
+ docInfoParam.notebook = protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
const titleEmpty = response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true";
tab.updateTitle(getDocDisplayName(response.data.name, titleEmpty));
if (protyle && protyle.title) {
@@ -62,9 +70,13 @@ export const reloadSync = (
};
allModels.editor.forEach(item => {
if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
- fetchPost("/api/block/getDocInfo", {
+ const docInfoParam: IObject = {
id: item.editor.protyle.block.rootID,
- }, (response) => {
+ };
+ if (isEncryptedBox(item.editor.protyle.notebookId)) {
+ docInfoParam.notebook = item.editor.protyle.notebookId;
+ }
+ fetchPost("/api/block/getDocInfo", docInfoParam, (response) => {
item.editor.protyle.wysiwyg.renderCustom(response.data.ial);
item.editor.reload(false, updateReadonly);
updateTitle(item.editor.protyle.block.rootID, item.parent, item.editor.protyle);
diff --git a/kernel/api/block.go b/kernel/api/block.go
index ac6c07e414..c06ccbf8c2 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -25,6 +25,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/html"
+ "github.com/88250/lute/parse"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
@@ -406,7 +407,13 @@ func getDocInfo(c *gin.Context) {
}
id := arg["id"].(string)
- info, err := model.GetDocInfo(id)
+ var info *model.BlockInfo
+ var err error
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ info, err = model.GetDocInfoInBox(id, notebook)
+ } else {
+ info, err = model.GetDocInfo(id)
+ }
if nil == info {
ret.Code = -1
if err != nil && !errors.Is(err, model.ErrTreeNotFound) {
@@ -726,7 +733,13 @@ func getBlockInfo(c *gin.Context) {
id := arg["id"].(string)
// 仅在此处使用带重建索引的加载函数,其他地方不要使用
- tree, err := model.LoadTreeByBlockIDWithReindex(id)
+ var tree *parse.Tree
+ var err error
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ tree, err = model.LoadTreeByBlockIDWithReindexInBox(id, notebook)
+ } else {
+ tree, err = model.LoadTreeByBlockIDWithReindex(id)
+ }
if err != nil {
if errors.Is(err, model.ErrIndexing) {
ret.Code = 3
@@ -957,7 +970,12 @@ func getBlockKramdown(c *gin.Context) {
}
}
- kramdown := model.GetBlockKramdown(id, mode)
+ var kramdown string
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ kramdown = model.GetBlockKramdownInBox(id, mode, notebook)
+ } else {
+ kramdown = model.GetBlockKramdown(id, mode)
+ }
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
@@ -1012,7 +1030,12 @@ func getBlockKramdowns(c *gin.Context) {
}
}
- kramdowns := model.GetBlockKramdowns(ids, mode)
+ var kramdowns map[string]string
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ kramdowns = model.GetBlockKramdownsInBox(ids, mode, notebook)
+ } else {
+ kramdowns = model.GetBlockKramdowns(ids, mode)
+ }
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 4678385a4e..6d8fcfa254 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -1013,11 +1013,16 @@ func processEmbedHTML(htmlStr string) string {
}
func GetBlockKramdown(id, mode string) (ret string) {
+ return GetBlockKramdownInBox(id, mode, "")
+}
+
+// GetBlockKramdownInBox 与 GetBlockKramdown 一致,但按 boxID 路由 blocktree 查询。
+func GetBlockKramdownInBox(id, mode, boxID string) (ret string) {
if "" == id {
return
}
- tree, err := LoadTreeByBlockID(id)
+ tree, err := loadTreeByBlockIDInBox(id, boxID)
if err != nil {
return
}
@@ -1027,6 +1032,11 @@ func GetBlockKramdown(id, mode string) (ret string) {
}
func GetBlockKramdowns(ids []string, mode string) (ret map[string]string) {
+ return GetBlockKramdownsInBox(ids, mode, "")
+}
+
+// GetBlockKramdownsInBox 与 GetBlockKramdowns 一致,但按 boxID 路由 blocktree 查询。
+func GetBlockKramdownsInBox(ids []string, mode, boxID string) (ret map[string]string) {
ret = make(map[string]string, len(ids))
if 0 == len(ids) {
return
@@ -1035,7 +1045,7 @@ func GetBlockKramdowns(ids []string, mode string) (ret map[string]string) {
luteEngine := NewLute()
for _, id := range ids {
// 节点会被移走,tree 不能共享,需重新加载
- tree, err := LoadTreeByBlockID(id)
+ tree, err := loadTreeByBlockIDInBox(id, boxID)
if err != nil {
continue
}
diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go
index 76df5a9f50..2280bca493 100644
--- a/kernel/model/blockinfo.go
+++ b/kernel/model/blockinfo.go
@@ -54,9 +54,14 @@ type AttrView struct {
}
func GetDocInfo(blockID string) (ret *BlockInfo, err error) {
+ return GetDocInfoInBox(blockID, "")
+}
+
+// GetDocInfoInBox 与 GetDocInfo 一致,但按 boxID 路由 blocktree/refs 查询到加密 db 或全局 db。
+func GetDocInfoInBox(blockID, boxID string) (ret *BlockInfo, err error) {
FlushTxQueue()
- tree, err := LoadTreeByBlockID(blockID)
+ tree, err := loadTreeByBlockIDInBox(blockID, boxID)
if err != nil {
logging.LogErrorf("load tree by root id [%s] failed: %s", blockID, err)
return
@@ -69,7 +74,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo, err error) {
if 0 < len(scrollData) {
// scroll 属性值在持久化时会被 html.EscapeAttrVal() 进行 HTML 转义(如 " 变为 &quot;),
// 虽然 parse.IAL2Map() 中会调用 html.UnescapeAttrVal() 进行反转义,
- // 但部分历史数据或某些路径下可能出现反转义不完整的情况,导致 JSON 解析失败,
+ // 但部分历史数据或某些历史路径下可能出现反转义不完整的情况,导致 JSON 解析失败,
// 这里做一次防御性反转义,确保 JSON 解析不会因为残留的 HTML 实体而报错
scrollData = util.UnescapeHTML(scrollData)
scroll := map[string]any{}
@@ -78,17 +83,17 @@ func GetDocInfo(blockID string) (ret *BlockInfo, err error) {
delete(ret.IAL, "scroll")
} else {
if zoomInId := scroll["zoomInId"]; nil != zoomInId {
- if !treenode.ExistBlockTree(zoomInId.(string)) {
+ if !treenode.ExistBlockTreeInBox(zoomInId.(string), boxID) {
delete(ret.IAL, "scroll")
}
} else {
if startId := scroll["startId"]; nil != startId {
- if !treenode.ExistBlockTree(startId.(string)) {
+ if !treenode.ExistBlockTreeInBox(startId.(string), boxID) {
delete(ret.IAL, "scroll")
}
}
if endId := scroll["endId"]; nil != endId {
- if !treenode.ExistBlockTree(endId.(string)) {
+ if !treenode.ExistBlockTreeInBox(endId.(string), boxID) {
delete(ret.IAL, "scroll")
}
}
@@ -96,8 +101,8 @@ func GetDocInfo(blockID string) (ret *BlockInfo, err error) {
}
}
- bt := treenode.GetBlockTree(blockID)
- refDefs := queryBlockRefDefs(bt)
+ bt := treenode.GetBlockTreeInBox(blockID, boxID)
+ refDefs := queryBlockRefDefsInBox(bt, boxID)
buildBacklinkListItemRefs(refDefs)
var refIDs []string
for _, refDef := range refDefs {
@@ -381,6 +386,11 @@ func GetBlockRefs(defID string) (refDefs []*RefDefs, originalRefBlockIDs map[str
}
func queryBlockRefDefs(bt *treenode.BlockTree) (refDefs []*RefDefs) {
+ return queryBlockRefDefsInBox(bt, "")
+}
+
+// queryBlockRefDefsInBox 与 queryBlockRefDefs 一致,但按 boxID 路由到加密 db 或全局 db。
+func queryBlockRefDefsInBox(bt *treenode.BlockTree, boxID string) (refDefs []*RefDefs) {
refDefs = []*RefDefs{}
if nil == bt {
return
@@ -388,7 +398,7 @@ func queryBlockRefDefs(bt *treenode.BlockTree) (refDefs []*RefDefs) {
isDoc := bt.ID == bt.RootID
if isDoc {
- refDefIDs := sql.QueryChildRefDefIDsByRootDefID(bt.RootID)
+ refDefIDs := sql.QueryChildRefDefIDsByRootDefIDInBox(bt.RootID, boxID)
for rID, dIDs := range refDefIDs {
var defIDs []string
for _, dID := range dIDs {
@@ -400,7 +410,7 @@ func queryBlockRefDefs(bt *treenode.BlockTree) (refDefs []*RefDefs) {
refDefs = append(refDefs, &RefDefs{RefID: rID, DefIDs: defIDs})
}
} else {
- refIDs := sql.QueryRefIDsByDefID(bt.ID, false)
+ refIDs := sql.QueryRefIDsByDefIDInBox(bt.ID, false, boxID)
for _, refID := range refIDs {
refDefs = append(refDefs, &RefDefs{RefID: refID, DefIDs: []string{bt.ID}})
}
diff --git a/kernel/model/tree.go b/kernel/model/tree.go
index f1275e33ea..60ad86b656 100644
--- a/kernel/model/tree.go
+++ b/kernel/model/tree.go
@@ -197,12 +197,17 @@ var (
)
func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
+ return LoadTreeByBlockIDWithReindexInBox(id, "")
+}
+
+// LoadTreeByBlockIDWithReindexInBox 与 LoadTreeByBlockIDWithReindex 一致,但按 boxID 路由 blocktree 查询。
+func LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err error) {
if "" == id {
logging.LogWarnf("block id is empty")
return nil, ErrTreeNotFound
}
- bt := treenode.GetBlockTree(id)
+ bt := treenode.GetBlockTreeInBox(id, boxID)
if nil == bt {
if task.ContainIndexTask() {
err = ErrIndexing
@@ -211,7 +216,7 @@ func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
// 尝试从文件系统加载并建立索引
err = indexTreeInFilesystem(id)
- bt = treenode.GetBlockTree(id)
+ bt = treenode.GetBlockTreeInBox(id, boxID)
if nil == bt {
if "dev" == util.Mode {
logging.LogWarnf("block tree not found [id=%s], stack: [%s]", id, logging.ShortStack())
diff --git a/kernel/sql/encrypted_query.go b/kernel/sql/encrypted_query.go
index 380668e791..7a0ab929d4 100644
--- a/kernel/sql/encrypted_query.go
+++ b/kernel/sql/encrypted_query.go
@@ -440,6 +440,56 @@ func QueryRefsRecentInBox(onlyDoc bool, typeFilter string, ignoreLines []string,
return
}
+// QueryChildRefDefIDsByRootDefIDInBox 按 rootDefID 查子引用定义,按 boxID 路由。
+func QueryChildRefDefIDsByRootDefIDInBox(rootDefID, boxID string) (ret map[string][]string) {
+ ret = map[string][]string{}
+ rows, err := queryForBox(boxID, "SELECT block_id, def_block_id FROM refs WHERE def_block_root_id = ?", rootDefID)
+ if err != nil {
+ logging.LogErrorf("sql query failed: %s", err)
+ return
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var defID, refID string
+ if err = rows.Scan(&defID, &refID); err != nil {
+ logging.LogErrorf("query scan field failed: %s", err)
+ return
+ }
+ if nil == ret[defID] {
+ ret[defID] = []string{refID}
+ } else {
+ ret[defID] = append(ret[defID], refID)
+ }
+ }
+ return
+}
+
+// QueryRefIDsByDefIDInBox 按 defID 查引用 ID 列表,按 boxID 路由。
+func QueryRefIDsByDefIDInBox(defID string, containChildren bool, boxID string) (refIDs []string) {
+ refIDs = []string{}
+ var rows *sql.Rows
+ var err error
+ if containChildren {
+ rows, err = queryForBox(boxID, "SELECT DISTINCT block_id FROM refs WHERE def_block_root_id = ?", defID)
+ } else {
+ rows, err = queryForBox(boxID, "SELECT DISTINCT block_id FROM refs WHERE def_block_id = ?", defID)
+ }
+ if err != nil {
+ logging.LogErrorf("sql query failed: %s", err)
+ return
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var id string
+ if err = rows.Scan(&id); err != nil {
+ logging.LogErrorf("query scan field failed: %s", err)
+ return
+ }
+ refIDs = append(refIDs, id)
+ }
+ return
+}
+
// SelectBlocksRawStmtNoParseInBox 与 SelectBlocksRawStmtNoParse 一致,但按 boxID 路由。
func SelectBlocksRawStmtNoParseInBox(stmt string, limit int, boxID string) (ret []*Block) {
rows, err := queryForBox(boxID, stmt)