An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Extend typed contracts for notebook and block APIs https://github.com/siyuan-note/siyuan/issues/19378
Daniela2661d88fb6d
diff --git a/app/src/block/popover.ts b/app/src/block/popover.tsindex 7adff8d024..850816bfbe 100644--- a/app/src/block/popover.ts+++ b/app/src/block/popover.ts@@ -585,6 +585,9 @@ export const showPopover = async (app: App, showRef = false) => {id: dataId,notebook: notebookId});+ if (postResponse.code !== 0) {+ return;+ }refDefs = postResponse.data.refDefs;originalRefBlockIDs = postResponse.data.originalRefBlockIDs;} else {@@ -601,6 +604,9 @@ export const showPopover = async (app: App, showRef = false) => {anchor: popoverTargetElement.textContent,notebook: notebookId});+ if (postResponse.code !== 0) {+ return;+ }refDefs = postResponse.data.refDefs;} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {// 以思源协议开头的链接diff --git a/app/src/block/util.ts b/app/src/block/util.tsindex d63fdfcf0a..c5dcb13be0 100644--- a/app/src/block/util.ts+++ b/app/src/block/util.ts@@ -45,6 +45,9 @@ export const getCancelSBOperations = async (nodeElement: Element, options: {id,notebook: options.notebookID,});+ if (response.code !== 0) {+ throw new Error(response.msg);+ }const template = document.createElement("template");template.innerHTML = normalizeHTMLAssetIFrameBlockDOM(response.data?.dom || "");const fullSuperBlockElement = template.content.querySelector(`[data-node-id="${id}"]`);diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex db5dfe3409..090a0593f1 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../../types/api";import {copyPlainText,isMac,@@ -715,7 +716,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {if (matchHotKey(window.siyuan.config.keymap.editor.general.rename, event)) {window.siyuan.menus.menu.remove();if (isFile) {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: liElements[0].getAttribute("data-node-id")};if (isEncryptedBox(notebookId)) {diff --git a/app/src/config/tabs/accessTab.ts b/app/src/config/tabs/accessTab.tsindex 03000e33d4..a7c2532a89 100644--- a/app/src/config/tabs/accessTab.ts+++ b/app/src/config/tabs/accessTab.ts@@ -1,5 +1,6 @@import type {SettingTabBuilder} from "../setting/builder";import {fetchPost, fetchSyncPost} from "../../util/fetch";+import {ContractFormData} from "../../util/contractFormData";import {Dialog} from "../../dialog";import {openInputDialog} from "../../dialog/inputDialog";import {confirmDialog} from "../../dialog/confirmDialog";@@ -735,7 +736,9 @@ const registerEncryptedNotebookGroup = (tab: SettingTabBuilder) => {desc: window.siyuan.languages.encryptedNotebookAutoLockDesc,min: 0,save: (value) => {- fetchPost("/api/notebook/setNotebookCryptoAutoLock", {autoLockMinutes: value});+ if (typeof value === "number") {+ fetchPost("/api/notebook/setNotebookCryptoAutoLock", {autoLockMinutes: value});+ }},});};@@ -769,10 +772,6 @@ const mountEncryptedNotebook = (root: HTMLElement) => {return;}fetchPost("/api/notebook/exportNotebookCryptoBackup", {}, async (response) => {- if (response.code === -1) {- showMessage(response.msg, 6000, "error");- return;- }const result = await saveExportFile(response.data.file);if (result.status === "success") {showMessage(window.siyuan.languages.exportNotebookCryptoBackupTip);@@ -816,14 +815,9 @@ const mountEncryptedNotebook = (root: HTMLElement) => {showMessage(window.siyuan.languages.masterPassword);return;}- const formData = new FormData();- formData.append("file", file);- formData.append("password", password);- fetch("/api/notebook/importNotebookCryptoBackup", {- method: "POST",- body: formData,- }).then((res) => res.json()).then((response: IWebSocketData) => {- if (response.code === -1) {+ const formData = new ContractFormData({file, password});+ fetchSyncPost("/api/notebook/importNotebookCryptoBackup", formData, undefined, false).then((response) => {+ if (response.code !== 0) {showMessage(response.msg, 6000, "error");return;}diff --git a/app/src/editor/deleteFile.ts b/app/src/editor/deleteFile.tsindex a2640d66f8..df1ca90c88 100644--- a/app/src/editor/deleteFile.ts+++ b/app/src/editor/deleteFile.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../types/api";import {fetchPost, fetchSyncPost} from "../util/fetch";import {getDisplayName, getNotebookName, isEncryptedBox} from "../util/pathName";import {confirmDialog} from "../dialog/confirmDialog";@@ -22,7 +23,7 @@ export const deleteFile = async (notebookId: string, pathString: string) => {});return;}- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: getDisplayName(pathString, true, true)};if (isEncryptedBox(notebookId)) {diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.tsindex 96c64ad4ff..66490de9a2 100644--- a/app/src/layout/dock/Outline.ts+++ b/app/src/layout/dock/Outline.ts@@ -1,4 +1,5 @@import {bindPanelSearch} from "./panelSearch";+import type {BlockBreadcrumbRequestInput} from "../../types/api";import {Tab} from "../Tab";import {Model} from "../Model";import {Tree} from "../../util/Tree";@@ -614,7 +615,7 @@ export class Outline extends Model {if (previousElement) {this.setCurrentById(previousElement.getAttribute("data-node-id"));} else {- const breadcrumbParam: Record<string, any> = {+ const breadcrumbParam: BlockBreadcrumbRequestInput = {id: nodeElement.getAttribute("data-node-id"),excludeTypes: []};@@ -1242,7 +1243,8 @@ export class Outline extends Model {fetchPost("/api/block/getHeadingDeleteTransaction", {id,}, async (deleteResponse) => {- const deletedIDs = deleteResponse.data.doOperations.map(+ const headingTransaction: {doOperations: IOperation[], undoOperations: IOperation[]} = deleteResponse.data;+ const deletedIDs = headingTransaction.doOperations.map((operation: IOperation) => operation.id);if (!await confirmBlockRef({scope: "blocks",@@ -1261,7 +1263,7 @@ export class Outline extends Model {if (!data.protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)) {return;}- deleteResponse.data.doOperations.forEach((operation: IOperation) => {+ headingTransaction.doOperations.forEach((operation: IOperation) => {data.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {itemElement.remove();});@@ -1270,19 +1272,19 @@ export class Outline extends Model {const newID = Lute.NewNodeID();const emptyElement = genEmptyElement(false, false, newID);data.protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);- deleteResponse.data.doOperations.push({+ headingTransaction.doOperations.push({action: "insert",data: emptyElement.outerHTML,id: newID,parentID: data.protyle.block.parentID});- deleteResponse.data.undoOperations.push({+ headingTransaction.undoOperations.push({action: "delete",id: newID,});focusBlock(emptyElement);}- transaction(data.protyle, deleteResponse.data.doOperations, deleteResponse.data.undoOperations);+ transaction(data.protyle, headingTransaction.doOperations, headingTransaction.undoOperations);});});}@@ -1298,7 +1300,8 @@ export class Outline extends Model {fetchPost("/api/block/getHeadingDeleteTransaction", {id,}, async (response) => {- const deletedIDs = response.data.doOperations.map((operation: IOperation) => operation.id);+ const headingTransaction: {doOperations: IOperation[], undoOperations: IOperation[]} = response.data;+ const deletedIDs = headingTransaction.doOperations.map((operation: IOperation) => operation.id);if (!await confirmBlockRef({scope: "blocks",ids: deletedIDs,@@ -1310,7 +1313,7 @@ export class Outline extends Model {if (!data.protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)) {return;}- response.data.doOperations.forEach((operation: IOperation) => {+ headingTransaction.doOperations.forEach((operation: IOperation) => {data.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {itemElement.remove();});@@ -1319,19 +1322,19 @@ export class Outline extends Model {const newID = Lute.NewNodeID();const emptyElement = genEmptyElement(false, false, newID);data.protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);- response.data.doOperations.push({+ headingTransaction.doOperations.push({action: "insert",data: emptyElement.outerHTML,id: newID,parentID: data.protyle.block.parentID});- response.data.undoOperations.push({+ headingTransaction.undoOperations.push({action: "delete",id: newID,});focusBlock(emptyElement);}- transaction(data.protyle, response.data.doOperations, response.data.undoOperations);+ transaction(data.protyle, headingTransaction.doOperations, headingTransaction.undoOperations);});}}).element);diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.tsindex 33c3dbb425..e7eaf1936c 100644--- a/app/src/layout/dock/util.ts+++ b/app/src/layout/dock/util.ts@@ -168,15 +168,17 @@ export const openOutline = async (options: {if (!wnd) {wnd = getWndByLayout(window.siyuan.layout.centerLayout);}- const newWnd = wnd.split("lr", false);-if (!options.title) {const response = await fetchSyncPost("/api/block/getDocInfo", {id: options.rootId,notebook: isEncryptedBox(options.notebookId) ? options.notebookId : undefined,});+ if (response.code !== 0) {+ return;+ }options.title = getDocDisplayName(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");}+ const newWnd = wnd.split("lr", false);newWnd.element.style.width = "200px";newWnd.element.classList.remove("fn__flex-1");fixWndFlex1(newWnd.parent);diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.tsindex ccd414afe9..74b518f1c9 100644--- a/app/src/menus/commonMenuItem.ts+++ b/app/src/menus/commonMenuItem.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../types/api";import {confirmDialog} from "../dialog/confirmDialog";import {getSearch, isMobile, isValidCustomAttrName} from "../util/functions";import {getAssetExtension, isEncryptedBox, isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";@@ -123,7 +124,7 @@ export const openWechatNotify = (nodeElement: Element) => {};export const openFileWechatNotify = (protyle: IProtyle) => {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {@@ -1073,7 +1074,7 @@ export const renameMenu = (options: {label: window.siyuan.languages.rename,click: () => {if (options.type === "file" && options.docId) {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: options.docId};if (isEncryptedBox(options.notebookId)) {diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.tsindex 74c837f57e..4d3f19a303 100644--- a/app/src/menus/navigation.ts+++ b/app/src/menus/navigation.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../types/api";import {copySubMenu, exportMd, movePathToMenu, openFileAttr, renameMenu,} from "./commonMenuItem";/// #if !BROWSERimport {FileFilter, ipcRenderer} from "electron";@@ -803,7 +804,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, llabel: window.siyuan.languages.attr,icon: "iconAttr",click() {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id};if (isEncryptedBox(notebookId)) {diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.tsindex 5210285a64..b9517cc259 100644--- a/app/src/mobile/dock/MobileOutline.ts+++ b/app/src/mobile/dock/MobileOutline.ts@@ -1,4 +1,5 @@import {bindPanelSearch} from "../../layout/dock/panelSearch";+import type {BlockBreadcrumbRequestInput} from "../../types/api";import {Tree} from "../../util/Tree";import {fetchPost} from "../../util/fetch";import {confirmBlockRef} from "../../util/checkBlockRef";@@ -460,7 +461,7 @@ export class MobileOutline extends Model {if (previousElement) {this.setCurrentById(previousElement.getAttribute("data-node-id"));} else {- const breadcrumbParam: Record<string, any> = {+ const breadcrumbParam: BlockBreadcrumbRequestInput = {id: nodeElement.getAttribute("data-node-id"),excludeTypes: []};@@ -1124,7 +1125,8 @@ export class MobileOutline extends Model {fetchPost("/api/block/getHeadingDeleteTransaction", {id,}, async (deleteResponse) => {- const deletedIDs = deleteResponse.data.doOperations.map(+ const headingTransaction: {doOperations: IOperation[], undoOperations: IOperation[]} = deleteResponse.data;+ const deletedIDs = headingTransaction.doOperations.map((operation: IOperation) => operation.id);if (!await confirmBlockRef({scope: "blocks",@@ -1143,7 +1145,7 @@ export class MobileOutline extends Model {if (!data.protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)) {return;}- deleteResponse.data.doOperations.forEach((operation: IOperation) => {+ headingTransaction.doOperations.forEach((operation: IOperation) => {data.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {itemElement.remove();});@@ -1152,19 +1154,19 @@ export class MobileOutline extends Model {const newID = Lute.NewNodeID();const emptyElement = genEmptyElement(false, false, newID);data.protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);- deleteResponse.data.doOperations.push({+ headingTransaction.doOperations.push({action: "insert",data: emptyElement.outerHTML,id: newID,parentID: data.protyle.block.parentID});- deleteResponse.data.undoOperations.push({+ headingTransaction.undoOperations.push({action: "delete",id: newID,});focusBlock(emptyElement);}- transaction(data.protyle, deleteResponse.data.doOperations, deleteResponse.data.undoOperations);+ transaction(data.protyle, headingTransaction.doOperations, headingTransaction.undoOperations);});});}@@ -1180,7 +1182,8 @@ export class MobileOutline extends Model {fetchPost("/api/block/getHeadingDeleteTransaction", {id,}, async (response) => {- const deletedIDs = response.data.doOperations.map((operation: IOperation) => operation.id);+ const headingTransaction: {doOperations: IOperation[], undoOperations: IOperation[]} = response.data;+ const deletedIDs = headingTransaction.doOperations.map((operation: IOperation) => operation.id);if (!await confirmBlockRef({scope: "blocks",ids: deletedIDs,@@ -1192,7 +1195,7 @@ export class MobileOutline extends Model {if (!data.protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)) {return;}- response.data.doOperations.forEach((operation: IOperation) => {+ headingTransaction.doOperations.forEach((operation: IOperation) => {data.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {itemElement.remove();});@@ -1201,19 +1204,19 @@ export class MobileOutline extends Model {const newID = Lute.NewNodeID();const emptyElement = genEmptyElement(false, false, newID);data.protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);- response.data.doOperations.push({+ headingTransaction.doOperations.push({action: "insert",data: emptyElement.outerHTML,id: newID,parentID: data.protyle.block.parentID});- response.data.undoOperations.push({+ headingTransaction.undoOperations.push({action: "delete",id: newID,});focusBlock(emptyElement);}- transaction(data.protyle, response.data.doOperations, response.data.undoOperations);+ transaction(data.protyle, headingTransaction.doOperations, headingTransaction.undoOperations);});}}).element);diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.tsindex f797574250..bf54cd1f0b 100644--- a/app/src/protyle/breadcrumb/index.ts+++ b/app/src/protyle/breadcrumb/index.ts@@ -1,3 +1,4 @@+import type {BlockBreadcrumbRequestInput, BlockQueryRequestInput, TreeStatRequestInput} from "../../types/api";import {getIconByType} from "../../editor/getIcon";import {fetchPost, fetchSyncPost} from "../../util/fetch";import {Constants} from "../../constants";@@ -135,7 +136,7 @@ ${padHTML}} else if (type === "doc") {// 不使用 window.siyuan.shiftIsPressed ,否则窗口未激活时按 Shift 点击块标无法打开属性面板 https://github.com/siyuan-note/siyuan/issues/15075if (event.shiftKey) {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {@@ -429,7 +430,7 @@ ${padHTML}private async genChildrenMenuItems(protyle: IProtyle, id: string, currentPathIDs: Set<string>,excludeTypes: string[], offset = 0): Promise<IMenu[]> {- const request: Record<string, any> = {+ const request = {id,offset,limit: 64,@@ -445,10 +446,10 @@ ${padHTML}if (rootID !== protyle.block.rootID) {return [];}- const data = response.data as {- items: IBreadcrumb[],- hasMore: boolean,- };+ if (response.code !== 0) {+ return [];+ }+ const data = response.data;if (!data?.items) {return [];}@@ -640,7 +641,7 @@ ${padHTML}return;}const id = blockElement.getAttribute("data-node-id");- const breadcrumbParam: Record<string, any> = {id, excludeTypes: [], notebook: protyle.notebookId};+ const breadcrumbParam: BlockBreadcrumbRequestInput = {id, excludeTypes: [], notebook: protyle.notebookId};this.mobileMenuLoading = true;const rootID = protyle.block.rootID;await waitForPendingTransactions(protyle);@@ -695,7 +696,7 @@ ${padHTML}if (cursorNodeElement) {id = cursorNodeElement.getAttribute("data-node-id");}- const statRequest: IObject = {+ const statRequest: TreeStatRequestInput = {id: id || (protyle.block.showAll ? protyle.block.id : protyle.block.rootID)};if (isEncryptedBox(protyle.notebookId)) {@@ -1170,7 +1171,7 @@ ${padHTML}// 闪卡面包屑不能显示答案excludeTypes.push("NodeTextMark-mark");}- const breadcrumbParam: Record<string, any> = {id, excludeTypes, notebook: protyle.notebookId};+ const breadcrumbParam = {id, excludeTypes, notebook: protyle.notebookId};// 等待当前块的创建事务完成,并丢弃切换文档或选择位置后过期的读取。const isCurrent = () => requestID === this.renderRequestID && rootID === protyle.block.rootID &&blockElement.isConnected;diff --git a/app/src/protyle/export/exportMd.ts b/app/src/protyle/export/exportMd.tsindex fe479191dc..0ca31f7ccf 100644--- a/app/src/protyle/export/exportMd.ts+++ b/app/src/protyle/export/exportMd.ts@@ -153,6 +153,9 @@ export const exportMarkdownZip = async(options: IExportMdOptions) => {if (options.id) {// 查询文档是否有子文档、引用及绑定的数据库,无则隐藏对应配置项 #17031const docInfo = await fetchSyncPost("/api/block/getDocInfo", {id: options.id});+ if (docInfo.code !== 0) {+ return;+ }const data = docInfo.data;showSubDocs = 0 < data.subFileCount;showRelatedDocs = 0 < (data.refCount || 0) || 0 < (data.attrViews?.length || 0);diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 3a6c6fa62d..11c98d7c9e 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -2126,6 +2126,9 @@ export class Gutter {id,notebook: protyle.notebookId,}).then((response) => {+ if (response.code !== 0) {+ return undefined;+ }const start = response.data?.start;return response.data?.found && typeof start === "number" && Number.isInteger(start) ? start : undefined;}).catch(() => undefined) : undefined;@@ -2687,7 +2690,8 @@ export class Gutter {fetchPost("/api/block/getHeadingDeleteTransaction", {id,}, async (deleteResponse) => {- const deletedIDs = deleteResponse.data.doOperations.map(+ const headingTransaction: {doOperations: IOperation[], undoOperations: IOperation[]} = deleteResponse.data;+ const deletedIDs = headingTransaction.doOperations.map((operation: IOperation) => operation.id);if (!await confirmBlockRef({scope: "blocks",@@ -2706,7 +2710,7 @@ export class Gutter {if (!protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)) {return;}- deleteResponse.data.doOperations.forEach((operation: IOperation) => {+ headingTransaction.doOperations.forEach((operation: IOperation) => {protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {itemElement.remove();});@@ -2715,19 +2719,19 @@ export class Gutter {const newID = Lute.NewNodeID();const emptyElement = genEmptyElement(false, false, newID);protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);- deleteResponse.data.doOperations.push({+ headingTransaction.doOperations.push({action: "insert",data: emptyElement.outerHTML,id: newID,parentID: protyle.block.parentID});- deleteResponse.data.undoOperations.push({+ headingTransaction.undoOperations.push({action: "delete",id: newID,});focusBlock(emptyElement);}- transaction(protyle, deleteResponse.data.doOperations, deleteResponse.data.undoOperations);+ transaction(protyle, headingTransaction.doOperations, headingTransaction.undoOperations);});});}@@ -2740,7 +2744,8 @@ export class Gutter {fetchPost("/api/block/getHeadingDeleteTransaction", {id,}, async (response) => {- const deletedIDs = response.data.doOperations.map((operation: IOperation) => operation.id);+ const headingTransaction: {doOperations: IOperation[], undoOperations: IOperation[]} = response.data;+ const deletedIDs = headingTransaction.doOperations.map((operation: IOperation) => operation.id);if (!await confirmBlockRef({scope: "blocks",ids: deletedIDs,@@ -2752,7 +2757,7 @@ export class Gutter {if (!protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)) {return;}- response.data.doOperations.forEach((operation: IOperation) => {+ headingTransaction.doOperations.forEach((operation: IOperation) => {protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {itemElement.remove();});@@ -2761,19 +2766,19 @@ export class Gutter {const newID = Lute.NewNodeID();const emptyElement = genEmptyElement(false, false, newID);protyle.wysiwyg.element.insertAdjacentElement("afterbegin", emptyElement);- response.data.doOperations.push({+ headingTransaction.doOperations.push({action: "insert",data: emptyElement.outerHTML,id: newID,parentID: protyle.block.parentID});- response.data.undoOperations.push({+ headingTransaction.undoOperations.push({action: "delete",id: newID,});focusBlock(emptyElement);}- transaction(protyle, response.data.doOperations, response.data.undoOperations);+ transaction(protyle, headingTransaction.doOperations, headingTransaction.undoOperations);});}}).element);@@ -4028,7 +4033,7 @@ export const addBlockToAgent = async (blockIds: string[]) => {let label = id;try {const resp = await fetchSyncPost("/api/block/getRefText", {id});- if (resp && resp.data) {+ if (resp.code === 0 && resp.data) {label = resp.data;}} catch {diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.tsindex 3505c24e1c..db61bae4f3 100644--- a/app/src/protyle/header/Title.ts+++ b/app/src/protyle/header/Title.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../../types/api";import {focusByOffset,focusByRange,@@ -165,7 +166,7 @@ export class Title {event.preventDefault();event.stopPropagation();} else if (matchHotKey(window.siyuan.config.keymap.editor.general.attr, event)) {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {@@ -186,7 +187,7 @@ export class Title {iconElement.addEventListener("click", (event) => {// 不使用 window.siyuan.shiftIsPressed ,否则窗口未激活时按 Shift 点击块标无法打开属性面板 https://github.com/siyuan-note/siyuan/issues/15075if (event.shiftKey) {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {@@ -325,7 +326,7 @@ export class Title {return;}/// #endif- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.tsindex f216ff9c08..a54a7186b9 100644--- a/app/src/protyle/header/openTitleMenu.ts+++ b/app/src/protyle/header/openTitleMenu.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../../types/api";import {fetchPost, fetchSyncPost} from "../../util/fetch";import {MenuItem} from "../../menus/Menu";import {copySubMenu, exportMd, movePathToMenu, openFileAttr, openFileWechatNotify,} from "../../menus/commonMenuItem";@@ -38,7 +39,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: striwindow.siyuan.menus.menu.remove();return;}- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {@@ -81,6 +82,9 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: stri})]);+ if (responseHTML.code !== 0 || responseText.code !== 0) {+ return;+ }const {textHTML, textSiyuan} = buildBlockDOMClipboardRichData(protyle.lute, responseHTML.data.dom);const result = await writeClipboardData({textPlain: responseText.data.content,diff --git a/app/src/protyle/toolbar/util.ts b/app/src/protyle/toolbar/util.tsindex ecb81e335c..0b1bcc8d62 100644--- a/app/src/protyle/toolbar/util.ts+++ b/app/src/protyle/toolbar/util.ts@@ -379,6 +379,9 @@ export const copyTextByType = async (ids: string[],}if (type === "ref") {const response = await fetchSyncPost("/api/block/getRefText", {id});+ if (response.code !== 0) {+ return;+ }text += `((${id} '${response.data}'))`;} else if (type === "blockEmbed") {text += `{{select * from blocks where id='${id}'}}`;@@ -386,6 +389,9 @@ export const copyTextByType = async (ids: string[],text += `siyuan://blocks/${id}`;} else if (type === "protocolMd") {const response = await fetchSyncPost("/api/block/getRefText", {id});+ if (response.code !== 0) {+ return;+ }text += `[${response.data.replace("[", "\\[").replace("]", "\\]")}](siyuan://blocks/${id})`;} else if (type === "hPath") {const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});diff --git a/app/src/protyle/util/blockFold.ts b/app/src/protyle/util/blockFold.tsindex 15a79448a9..fb7f7053fe 100644--- a/app/src/protyle/util/blockFold.ts+++ b/app/src/protyle/util/blockFold.ts@@ -245,8 +245,11 @@ export const foldHeadingGroup = async (protyle: IProtyle, nodeElement: Element,}const id = nodeElement.getAttribute("data-node-id");const response = await fetchSyncPost("/api/block/getHeadingFoldTransaction", {id, scope});- const doOperations = response.data?.doOperations as IOperation[];- const undoOperations = response.data?.undoOperations as IOperation[];+ if (response.code !== 0) {+ return;+ }+ const doOperations = response.data?.doOperations;+ const undoOperations = response.data?.undoOperations;if (!doOperations || !undoOperations || doOperations.length === 0) {return;}@@ -328,6 +331,9 @@ const foldBlocksRecursively0 = async (protyle: IProtyle, nodeElements: Element[]id: element.getAttribute("data-node-id"),notebook: protyle.notebookId,});+ if (response.code !== 0) {+ throw new Error(response.msg);+ }fullHTML = response.data.dom;}return {element, fullHTML, occurrenceID: getViewFoldOccurrenceID(protyle, element)};diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 200f617f42..a14c2d59d8 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -693,6 +693,9 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemenfor (let j = 0; j < copyFoldHeadingIds.length; j++) {const childrenItem = copyFoldHeadingIds[j];const responseTransaction = await fetchSyncPost("/api/block/getHeadingInsertTransaction", {id: childrenItem.oldId});+ if (responseTransaction.code !== 0) {+ throw new Error(responseTransaction.msg);+ }responseTransaction.data.doOperations.splice(0, 1);responseTransaction.data.doOperations[0].previousID = childrenItem.newId;responseTransaction.data.undoOperations.splice(0, 1);diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex e0d260e4c2..37dcc4a3ef 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../../types/api";import {Constants} from "../../constants";import {hideElements} from "../ui/hideElements";import {fetchPost} from "../../util/fetch";@@ -213,7 +214,7 @@ export const onGet = (options: {return;}- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: options.protyle.block.rootID};if (isEncryptedBox(options.protyle.notebookId)) {diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.tsindex 0de5e5b703..677152795c 100644--- a/app/src/protyle/util/paste.ts+++ b/app/src/protyle/util/paste.ts@@ -1095,6 +1095,9 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvenoldIds.push(e.getAttribute("data-node-id"));});const existResponse = await fetchSyncPost("/api/block/checkBlocksExist", {ids: oldIds});+ if (existResponse.code !== 0) {+ return;+ }range = restorePasteInsertRange();if (!range) {return;diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.tsindex 867428aa4e..4891444ac2 100644--- a/app/src/protyle/wysiwyg/commonHotkey.ts+++ b/app/src/protyle/wysiwyg/commonHotkey.ts@@ -298,6 +298,9 @@ export const duplicateBlock = async (nodeElements: Element[], protyle: IProtyle)id: item.getAttribute("data-node-id"),notebook: protyle.notebookId,});+ if (response.code !== 0) {+ return;+ }const foldTempElement = document.createElement("template");foldTempElement.innerHTML = normalizeHTMLAssetIFrameBlockDOM(response.data.dom);tempElement = foldTempElement.content.firstElementChild as HTMLElement;diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 490ca11f9a..78c9302978 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -845,6 +845,9 @@ export class WYSIWYG {id: item.getAttribute("data-node-id"),notebook: protyle.notebookId,});+ if (response.code !== 0) {+ return;+ }itemHTML = response.data.dom;} else {itemHTML = removeEmbed(item);@@ -3200,6 +3203,10 @@ export class WYSIWYG {id: item.getAttribute("data-node-id"),notebook: protyle.notebookId,});+ if (response.code !== 0) {+ clearAutoSelectedBlock();+ return;+ }itemHTML = response.data.dom;} else {itemHTML = removeEmbed(item);diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 4e20387709..5ac5de88ac 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../../types/api";import {hideElements} from "../ui/hideElements";import {isTabTextBoundary} from "./tabsBoundary";import {isNotCtrl, isOnlyMeta, updateHotkeyTip, writeText} from "../util/compatibility";@@ -1754,7 +1755,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {}if (matchHotKey(window.siyuan.config.keymap.editor.general.rename, event) && !protyle.disabled) {if (selectText === "") {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: protyle.block.rootID};if (isEncryptedBox(protyle.notebookId)) {diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.tsindex 3ea7558990..6d191a576c 100644--- a/app/src/protyle/wysiwyg/list.ts+++ b/app/src/protyle/wysiwyg/list.ts@@ -169,6 +169,9 @@ const getListElementByID = async (protyle: IProtyle, listID: string) => {id: listID,notebook: protyle.notebookId,});+ if (response.code !== 0) {+ return;+ }const template = document.createElement("template");template.innerHTML = normalizeHTMLAssetIFrameBlockDOM(response.data?.dom || "");const listElement = template.content.firstElementChild as HTMLElement;@@ -364,7 +367,10 @@ const getFocusedListTailItem = async (protyle: IProtyle, listID: string, currentn: 1,notebook: protyle.notebookId,});- const tailBlock = tailResponse.data?.[0] as {id?: string, type?: string} | undefined;+ if (tailResponse.code !== 0) {+ return;+ }+ const tailBlock = tailResponse.data?.[0];if (!tailBlock?.id || tailBlock.type !== "i") {return;}@@ -376,6 +382,9 @@ const getFocusedListTailItem = async (protyle: IProtyle, listID: string, currentid: tailBlock.id,notebook: protyle.notebookId,});+ if (domResponse.code !== 0) {+ return;+ }const template = document.createElement("template");template.innerHTML = domResponse.data?.dom || "";const tailItemElement = template.content.firstElementChild as HTMLElement;diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex 0384bb5299..64f689641f 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -1148,6 +1148,9 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangconst foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {id: foldId,});+ if (foldTransaction.code !== 0) {+ return;+ }unfoldData[foldId] = {element: foldPreviousBlockElement,previousID: foldTransaction.data.doOperations[foldTransaction.data.doOperations.length - 1].id@@ -1176,6 +1179,9 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangconst foldTransaction = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {id: foldId,});+ if (foldTransaction.code !== 0) {+ return;+ }unfoldData[foldId] = {element: previousBlockElement,previousID: foldTransaction.data.doOperations[foldTransaction.data.doOperations.length - 1].iddiff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex a8f333f3bf..29e2a3f8c8 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -2194,6 +2194,9 @@ export const turnsOneInto = async (options: {id: options.id,notebook: options.protyle.notebookId,});+ if (response.code !== 0) {+ return;+ }if (!source.isConnected || source.outerHTML !== snapshot) {return;}diff --git a/app/src/search/util.ts b/app/src/search/util.tsindex 26bbbb36db..52fc13eac0 100644--- a/app/src/search/util.ts+++ b/app/src/search/util.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../types/api";import {getAllModels} from "../layout/getAll";/// #if !BROWSERimport * as path from "path";@@ -1265,7 +1266,7 @@ export const getArticle = (options: {}options.edit.protyle.scroll.lastScrollTop = 0;addLoading(options.edit.protyle);- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: options.id,};if (isEncryptedBox(options.edit.protyle.notebookId)) {diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.tsindex 07c5e0266f..3c472cf369 100644--- a/app/src/types/api/index.d.ts+++ b/app/src/types/api/index.d.ts@@ -1,11 +1,31 @@// 此文件由内核契约生成,请运行 pnpm run api:generate 更新。+export type AppendBlockRequestInput = { "data": string; "dataType": string; "parentID": string; };+export type AppendHeadingChildrenRequestInput = { "childrenDOM": string; "id": string; };export type AutoLaunchRequestInput = { "autoLaunch": number; };+export type BatchInsertBlockRequestInput = { "blocks": Array<BlockInsertInputInput>; };++export type BatchParentBlockRequestInput = { "blocks": Array<PrependBlockRequestInput>; };+export type BatchSetBlockAttrsRequestInput = { "blockAttrs": Array<SetBlockAttrsRequestInput>; };+export type BatchTaskListMarkerRequestInput = { "items": Array<TaskListMarkerRequestInput>; };++export type BatchUpdateBlockRequestInput = { "blocks": Array<UpdateBlockRequestInput>; };++export type BlockBreadcrumbChildren = { "hasMore": boolean; "items": Array<BlockPath | null> | null; };++export type BlockBreadcrumbChildrenRequestInput = { "excludeTypes"?: Array<string> | null; "id": string; "ids"?: Array<string> | null; "limit"?: number | null; "notebook"?: string | null; "offset"?: number | null; };++export type BlockBreadcrumbRequestInput = { "excludeTypes"?: Array<string> | null; "id": string; "ids"?: Array<string> | null; "notebook"?: string | null; };++export type BlockDOMData = { "dom": string; "id": string; };++export type BlockDeleteData = { "createEmptyParagraph": boolean; };+export type BlockFoldData = { "isFolded": boolean; "isRoot": boolean; };export type BlockIDRequestInput = { "id": string; };@@ -16,22 +36,54 @@ export type BlockInfoData = (FullBlockInfo & { "publishAccessRequired"?: never;export type BlockInfoRequestInput = { "id": string; "ids"?: Array<string> | null; "notebook"?: string | null; };+export type BlockInsertInputInput = { "data": string; "dataType": string; "nextID"?: string | null; "parentID"?: string | null; "previousID"?: string | null; };++export type BlockKramdownData = { "id": string; "kramdown": string; };++export type BlockKramdownRequestInput = { "id": string; "ids"?: Array<string> | null; "mode"?: string | null; "notebook"?: string | null; };++export type BlockOperation = { "action": "delete" | "insert" | "update" | "foldHeading" | "unfoldHeading" | "setAttrs" | "moveOutlineHeading" | "appendInsert" | "prependInsert"; "avID": string; "backRelationKeyID": string; "blockID": string; "blockIDs": Array<string> | null; "context": Record<string, string> | null; "data": null | string | BlockDeleteData; "deckID": string; "format": string; "groupID": string; "id": string; "ignoreDefaultFill": boolean; "isDetached": boolean; "isTwoWay": boolean; "keyID": string; "layout": string; "name": string; "nextID": string; "parentID": string; "previousID": string; "removeDest": boolean; "retData": null | string | Array<string>; "rootID": string; "rowID": string; "srcIDs": Array<string> | null; "srcs": null; "targetGroupID": string; "type": ""; "viewID": string; "viewIDs"?: Array<string>; };++export type BlockPath = { "children": Array<BlockPath | null> | null; "hasChildren"?: boolean; "id": string; "name": string; "subType": string; "type": string; };+export type BlockQueryRequestInput = { "id": string; "ids"?: Array<string> | null; "notebook"?: string | null; };export type BlockRelevantData = { "nextID": string; "parentID": string; "previousID": string; };+export type BlockReminderRequestInput = { "id": string; "timed": string; };+export type BlockSiblingData = { "next": string; "parent": string; "previous": string; };+export type BlockStat = { "blockCount": number; "imageCount": number; "linkCount": number; "refCount": number; "runeCount": number; "wordCount": number; };++export type BlockTransaction = { "doOperations": Array<BlockOperation | null> | null; "templateDocTreePlanID"?: string; "timestamp": number; "undoOperations": Array<BlockOperation | null> | null; };++export type BlockTreeInfo = { "id": string; "nextID": string; "nextType": string; "parentID": string; "parentType": string; "previousID": string; "previousType": string; "type": string; };++export type BlocksKramdownRequestInput = { "id"?: string | null; "ids": Array<string>; "mode"?: string | null; "notebook"?: string | null; };+export type BlocksQueryRequestInput = { "id"?: string | null; "ids": Array<string>; "notebook"?: string | null; };+export type BlocksWordCountRequestInput = { "id"?: string | null; "ids": Array<string>; "notebook"?: string | null; "reqId"?: JSONValue | null; };+export type BootProgressData = { "details": string; "progress": number; };+export type ChangeMasterPasswordRequestInput = { "newPassword": string; "oldPassword": string; };+export type ChangeSortNotebookRequestInput = { "notebooks": Array<string>; };+export type CheckBlocksExistRequestInput = { "id"?: string | null; "ids": Array<JSONValue>; "notebook"?: string | null; };+export type CheckSnapshotData = { "changed": boolean; };+export type ChildBlock = { "content"?: string; "id": string; "markdown"?: string; "subType"?: string; "type": string; };+export type CloseNotebookRequestInput = { "notebook": string; };+export type ContentWordCountRequestInput = { "content": string; "reqId"?: JSONValue | null; };++export type CreateEncryptedNotebookRequestInput = { "name": string; "password": string; };+export type CreateNotebookData = { "notebook": Notebook | null; };export type CreateNotebookRequestInput = { "name": string; };@@ -42,26 +94,54 @@ export type CreateSnapshotRequestInput = { "memo"?: string; };export type DOMTextRequestInput = { "dom": string; };+export type DailyNoteBlockRequestInput = { "data": string; "dataType": string; "notebook": string; };++export type DeleteBlockRequestInput = { "id": string; };++export type DocAttrView = { "id": string; "name": string; };++export type DocInfo = { "attrViews": Array<DocAttrView | null> | null; "ial": Record<string, string> | null; "icon": string; "id": string; "name": string; "refCount": number; "refIDs": Array<string> | null; "rootID": string; "subFileCount": number; };+export type DocOrdersRequestInput = { "id": string; };+export type DocsInfoRequestInput = { "av": boolean; "ids": Array<string>; "refCount": boolean; };+export type DownloadInstallPkgRequestInput = { "downloadInstallPkg": boolean; };export type EditorReadOnlyRequestInput = { "readonly": boolean; };+export type EmbedStat = { "complete": boolean; "cycleCount": number; "depthLimitCount": number; "failedQueryCount": number; "failedResultCount": number; "jsEmbedCount": number; "queryEmbedCount": number; "resultCount": number; "truncatedQueryCount": number; };+export type EmptyRequestInput = Record<string, never>;+export type EncryptedNotebookStatus = { "id": string; "name": string; "state": "Locked" | "Unlocking" | "Unlocked" | "Locking" | "Error"; "unlocked": boolean; };++export type EncryptedNotebookStatusData = { "boxes": Array<EncryptedNotebookStatus>; "count": number; "enabled": boolean; "hasHistoryDependency": boolean; "migrationBoxes": Array<string> | null; "migrationPending": boolean; "state": "Disabled" | "Enabled" | "RecoveryRequired"; };++export type FileAnnotationRefRequestInput = { "id": string; "notebook"?: string | null; };+export type FullBlockInfo = { "box": string; "path": string; "rootChildID": string; "rootID": string; "rootIcon": string; "rootTitle": string; "rootTitleEmpty": boolean; };export type GetTagRequestInput = { "app"?: string | null; "ignoreMaxListHint"?: boolean | null; "sort"?: number | null; };export type HeadingChildrenRequestInput = { "id": string; "removeFoldAttr"?: boolean | null; };+export type HeadingFoldRequestInput = { "id": string; "scope": string; };++export type ImportNotebookCryptoBackupRequestInput = { "file": Blob; "password"?: string; };++export type InsertBlockRequestInput = { "data": string; "dataType": string; "nextID"?: string | null; "parentID"?: string | null; "previousID"?: string | null; };++export type JSONValue = null | boolean | number | string | Array<JSONValue> | { [key: string]: JSONValue };+export type ListNotebooksData = { "boxDocEnabled": boolean; "notebooks": Array<Notebook | null> | null; };export type ListNotebooksRequestInput = { "flashcard"?: boolean | null; };export type LockScreenRequestInput = { "lockScreenMode": number; };+export type MoveBlockRequestInput = { "id": string; "parentID"?: string | null; "previousID"?: string | null; };+export type NetworkData = { "proxy": NetworkProxy | null; };export type NetworkProxy = { "host": string; "port": string; "scheme": string; };@@ -74,12 +154,48 @@ export type NetworkServeTLSRequestInput = { "networkServeTLS": boolean; };export type Notebook = { "closed": boolean; "dueFlashcardCount": number; "encrypted": boolean; "flashcardCount": number; "icon": string; "id": string; "name": string; "newFlashcardCount": number; "sort": number; "sortMode": number; "state"?: "Locked" | "Unlocking" | "Unlocked" | "Locking" | "Error"; "subFileCount": number; "unlocked": boolean; };+export type NotebookConf = { "boxCrypt": NotebookEncryption | null; "closed": boolean; "dailyNoteSavePath": string; "dailyNoteTemplatePath": string; "docCreateSaveBox": string; "docCreateSavePath": string; "docCreateTemplatePath": string; "encrypted": boolean; "icon": string; "name": string; "refCreateSaveBox": string; "refCreateSavePath": string; "sort": number; "sortMode": number; };++export type NotebookConfData = { "box": string; "conf": NotebookConf | null; "name": string; };++export type NotebookConfPatchInput = { "boxCrypt"?: NotebookEncryptionPatchInput | null; "closed"?: boolean | null; "dailyNoteSavePath"?: string | null; "dailyNoteTemplatePath"?: string | null; "docCreateSaveBox"?: string | null; "docCreateSavePath"?: string | null; "docCreateTemplatePath"?: string | null; "encrypted"?: boolean | null; "icon"?: string | null; "name"?: string | null; "refCreateSaveBox"?: string | null; "refCreateSavePath"?: string | null; "sort"?: number | null; "sortMode"?: number | null; };++export type NotebookCryptoAutoLockRequestInput = { "autoLockMinutes": number; };++export type NotebookCryptoBackupData = { "file": string; };++export type NotebookEncryption = { "createdAt": number; "metadata"?: string; "spec": number; "wrapNonce": string | null; "wrappedDEK": string | null; };++export type NotebookEncryptionPatchInput = { "createdAt"?: number | null; "metadata"?: string | Array<number> | null; "spec"?: number | null; "wrapNonce"?: string | Array<number> | null; "wrappedDEK"?: string | Array<number> | null; };+export type NotebookIDRequestInput = { "notebook": string; };+export type NotebookInfo = { "ctime": number; "docCount": number; "hCtime": string; "hMtime": string; "hSize": string; "id": string; "mtime": number; "name": string; "size": number; };++export type NotebookInfoData = { "boxInfo": NotebookInfo | null; };++export type NotebookPasswordRequestInput = { "password": string; };++export type OpenNotebookRequestInput = { "app"?: string | null; "notebook": string; };++export type OrderedListStartData = { "found": boolean; "start": number; };+export type PinnedDoc = { "childrenSortMode": number | null; "icon": string; "id": string; "name": string; "notebook": string; "path": string; "subFileCount": number; "unavailable": boolean; };+export type PrependBlockRequestInput = { "data": string; "dataType": string; "parentID": string; };+export type PublishedBlockInfo = { "publishAccessRequired": true; "rootID": string; "rootIcon": string; "rootTitle": string; "rootTitleEmpty": boolean; };+export type RefDefs = { "defIDs": Array<string> | null; "refID": string; };++export type RefDefsData = { "refDefs": Array<RefDefs>; };++export type RefIDsData = { "originalRefBlockIDs": Record<string, string> | null; "refDefs": Array<RefDefs | null> | null; };++export type RefIDsRequestInput = { "id"?: string | null; "ids"?: Array<string> | null; "notebook"?: string | null; };++export type RefTextQueryRequestInput = { "anchor": string; "notebook"?: string | null; };+export type RemoveBookmarkRequestInput = { "bookmark": string; };export type RemoveTagRequestInput = { "label": string; };@@ -90,6 +206,10 @@ export type RenameNotebookRequestInput = { "name": string; "notebook": string; }export type RenameTagRequestInput = { "newLabel": string; "oldLabel": string; };+export type ReorderData = { "changed": boolean; "notebook"?: string; "parentPath"?: string; };++export type ReorderNotebooksRequestInput = { "position"?: string | null; "sourceIDs"?: Array<string> | null; "targetID"?: string | null; };+export type SearchHistoryData = { "histories": Array<string> | null; "pageCount": number; "totalCount": number; };export type SearchHistoryRequestInput = { "notebook"?: string | null; "op"?: string | null; "page"?: number | null; "query"?: string | null; "type"?: number | null; };@@ -100,20 +220,40 @@ export type SearchTagRequestInput = { "k": string; };export type SetBlockAttrsRequestInput = { "attrs": Record<string, string | null>; "id": string; };+export type SetNotebookConfRequestInput = { "conf"?: NotebookConfPatchInput | null; "notebook": string; };+export type SetNotebookIconRequestInput = { "icon": string; "notebook": string; };export type SetSnapshotMemoRequestInput = { "id": string; "memo": string; };+export type SwapBlockRefRequestInput = { "defID": string; "includeChildren": boolean; "refID": string; };+export type TagData = { "children": Array<TagData | null> | null; "count": number; "depth": number; "label": string; "name": string; "type": string; };+export type TailChildBlocksRequestInput = { "id": string; "ids"?: Array<string> | null; "n"?: number | null; "notebook"?: string | null; };++export type TaskListMarkerRequestInput = { "id": string; "marker": string; };++export type TransferBlockRefRequestInput = { "fromID": string; "refIDs"?: Array<string> | null; "reloadUI"?: boolean | null; "toID": string; };++export type TreeStatData = { "containsEmbed"?: boolean; "embedStat"?: EmbedStat | null; "reqId": JSONValue; "stat": BlockStat | null; "statWithEmbed"?: BlockStat | null; };++export type TreeStatRequestInput = { "id": string; "ids"?: Array<string> | null; "includeEmbed"?: boolean | null; "notebook"?: string | null; "reqId"?: JSONValue | null; };+export type UnfoldedParentData = { "parentID": string; };+export type UnlockNotebookRequestInput = { "notebook": string; "password": string; };++export type UpdateBlockRequestInput = { "data": string; "dataType": string; "id": string; "lockType"?: boolean | null; };+export type UpdateChannelRequestInput = { "updateChannel": string; };export type UpdatePinnedDocsRequestInput = { "action": string; "after"?: boolean; "ids": Array<string>; "targetID"?: string; };export type VirtualBlockRefRequestInput = { "keywords": Array<string>; };+export type WordCountData = { "reqId": JSONValue; "stat": BlockStat | null; };+export type WorkspaceInfoData = { "siyuanVer": string; "workspaceDir": string; };export type APILegacyGETPath =@@ -292,55 +432,10 @@ export type APILegacyPOSTPath ="/api/bazaar/uninstallBazaarTheme" |"/api/bazaar/uninstallBazaarWidget" |"/api/bazaar/updateBazaarPackage" |- "/api/block/appendBlock" |- "/api/block/appendDailyNoteBlock" |- "/api/block/batchAppendBlock" |- "/api/block/batchInsertBlock" |- "/api/block/batchPrependBlock" |- "/api/block/batchUpdateBlock" |- "/api/block/batchUpdateTaskListItemMarker" |"/api/block/checkBlockRef" |- "/api/block/checkBlocksExist" |- "/api/block/deleteBlock" |- "/api/block/foldBlock" |- "/api/block/getBlockBreadcrumb" |- "/api/block/getBlockBreadcrumbChildren" |- "/api/block/getBlockDOM" |- "/api/block/getBlockDOMWithEmbed" |- "/api/block/getBlockDOMs" |- "/api/block/getBlockDOMsWithEmbed" |- "/api/block/getBlockDefIDsByRefText" |- "/api/block/getBlockKramdown" |- "/api/block/getBlockKramdowns" |- "/api/block/getBlockTreeInfos" |- "/api/block/getBlocksWordCount" |- "/api/block/getChildBlocks" |- "/api/block/getContentWordCount" |"/api/block/getDocHeadingLevelTransaction" |- "/api/block/getDocInfo" |- "/api/block/getDocsInfo" |- "/api/block/getHeadingDeleteTransaction" |- "/api/block/getHeadingFoldTransaction" |- "/api/block/getHeadingInsertTransaction" |"/api/block/getHeadingLevelTransaction" |- "/api/block/getOrderedListContinueStart" |"/api/block/getRecentUpdatedBlocks" |- "/api/block/getRefIDs" |- "/api/block/getRefIDsByFileAnnotationID" |- "/api/block/getRefText" |- "/api/block/getTailChildBlocks" |- "/api/block/getTreeStat" |- "/api/block/insertBlock" |- "/api/block/moveBlock" |- "/api/block/moveOutlineHeading" |- "/api/block/prependBlock" |- "/api/block/prependDailyNoteBlock" |- "/api/block/setBlockReminder" |- "/api/block/swapBlockRef" |- "/api/block/transferBlockRef" |- "/api/block/unfoldBlock" |- "/api/block/updateBlock" |- "/api/block/updateTaskListItemMarker" |"/api/bookmark/getBookmark" |"/api/broadcast/getChannelInfo" |"/api/broadcast/getChannels" |@@ -476,23 +571,6 @@ export type APILegacyPOSTPath ="/api/network/echo/*path" |"/api/network/forwardProxy" |"/api/network/proxy" |- "/api/notebook/changeMasterPassword" |- "/api/notebook/createEncryptedNotebook" |- "/api/notebook/disableEncryptedNotebooks" |- "/api/notebook/enableEncryptedNotebooks" |- "/api/notebook/exportNotebookCryptoBackup" |- "/api/notebook/getEncryptedNotebookStatus" |- "/api/notebook/getNotebookConf" |- "/api/notebook/getNotebookInfo" |- "/api/notebook/importNotebookCryptoBackup" |- "/api/notebook/lockNotebook" |- "/api/notebook/openNotebook" |- "/api/notebook/reorder" |- "/api/notebook/setNotebookConf" |- "/api/notebook/setNotebookCryptoAutoLock" |- "/api/notebook/touchEncryptedNotebooks" |- "/api/notebook/unlockAndOpenNotebook" |- "/api/notebook/unlockNotebook" |"/api/notification/pushErrMsg" |"/api/notification/pushMsg" |"/api/outline/getDocHeadingNumbers" |@@ -729,11 +807,46 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/appendBlock": {+ request: AppendBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/appendDailyNoteBlock": {+ request: DailyNoteBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/appendHeadingChildren": {request: AppendHeadingChildrenRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/batchAppendBlock": {+ request: BatchParentBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/batchInsertBlock": {+ request: BatchInsertBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/batchPrependBlock": {+ request: BatchParentBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/batchUpdateBlock": {+ request: BatchUpdateBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/batchUpdateTaskListItemMarker": {+ request: BatchTaskListMarkerRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/checkBlockExist": {request: BlockQueryRequestInput;response: { "code": 0; "data": boolean; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -744,6 +857,56 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": BlockFoldData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/checkBlocksExist": {+ request: CheckBlocksExistRequestInput;+ response: { "code": 0; "data": Record<string, boolean> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/deleteBlock": {+ request: DeleteBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/foldBlock": {+ request: BlockIDRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockBreadcrumb": {+ request: BlockBreadcrumbRequestInput;+ response: { "code": 0; "data": Array<BlockPath | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockBreadcrumbChildren": {+ request: BlockBreadcrumbChildrenRequestInput;+ response: { "code": 0; "data": BlockBreadcrumbChildren | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockDOM": {+ request: BlockQueryRequestInput;+ response: { "code": 0; "data": BlockDOMData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockDOMWithEmbed": {+ request: BlockQueryRequestInput;+ response: { "code": 0; "data": BlockDOMData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockDOMs": {+ request: BlocksQueryRequestInput;+ response: { "code": 0; "data": Record<string, string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockDOMsWithEmbed": {+ request: BlocksQueryRequestInput;+ response: { "code": 0; "data": Record<string, string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockDefIDsByRefText": {+ request: RefTextQueryRequestInput;+ response: { "code": 0; "data": RefDefsData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/getBlockIndex": {request: BlockQueryRequestInput;response: { "code": 0; "data": number; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -754,6 +917,16 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": BlockInfoData; "msg": string; } | { "code": -1 | 3; "data": { "closeTimeout": number; } | null | string; "msg": string; };body: "json";};+ "/api/block/getBlockKramdown": {+ request: BlockKramdownRequestInput;+ response: { "code": 0; "data": BlockKramdownData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getBlockKramdowns": {+ request: BlocksKramdownRequestInput;+ response: { "code": 0; "data": Record<string, string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/getBlockRelevantIDs": {request: BlockQueryRequestInput;response: { "code": 0; "data": BlockRelevantData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -764,11 +937,31 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": BlockSiblingData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/getBlockTreeInfos": {+ request: BlocksQueryRequestInput;+ response: { "code": 0; "data": Record<string, BlockTreeInfo | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/getBlocksIndexes": {request: BlocksQueryRequestInput;response: { "code": 0; "data": Record<string, number> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/getBlocksWordCount": {+ request: BlocksWordCountRequestInput;+ response: { "code": 0; "data": WordCountData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getChildBlocks": {+ request: BlockQueryRequestInput;+ response: { "code": 0; "data": Array<ChildBlock | null>; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getContentWordCount": {+ request: ContentWordCountRequestInput;+ response: { "code": 0; "data": WordCountData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/getDOMText": {request: DOMTextRequestInput;response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -779,6 +972,16 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": Array<string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/getDocInfo": {+ request: BlockQueryRequestInput;+ response: { "code": 0; "data": DocInfo | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getDocsInfo": {+ request: DocsInfoRequestInput;+ response: { "code": 0; "data": Array<DocInfo | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/getHeadingChildrenDOM": {request: HeadingChildrenRequestInput;response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -789,11 +992,111 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": Array<string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/getHeadingDeleteTransaction": {+ request: BlockIDRequestInput;+ response: { "code": 0; "data": BlockTransaction | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getHeadingFoldTransaction": {+ request: HeadingFoldRequestInput;+ response: { "code": 0; "data": BlockTransaction | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getHeadingInsertTransaction": {+ request: BlockIDRequestInput;+ response: { "code": 0; "data": BlockTransaction | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getOrderedListContinueStart": {+ request: BlockQueryRequestInput;+ response: { "code": 0; "data": OrderedListStartData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getRefIDs": {+ request: RefIDsRequestInput;+ response: { "code": 0; "data": RefIDsData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getRefIDsByFileAnnotationID": {+ request: FileAnnotationRefRequestInput;+ response: { "code": 0; "data": RefDefsData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getRefText": {+ request: BlockQueryRequestInput;+ response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getTailChildBlocks": {+ request: TailChildBlocksRequestInput;+ response: { "code": 0; "data": Array<ChildBlock | null>; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/getTreeStat": {+ request: TreeStatRequestInput;+ response: { "code": 0; "data": TreeStatData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/block/getUnfoldedParentID": {request: BlockQueryRequestInput;response: { "code": 0; "data": UnfoldedParentData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/block/insertBlock": {+ request: InsertBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/moveBlock": {+ request: MoveBlockRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/moveOutlineHeading": {+ request: MoveBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/prependBlock": {+ request: PrependBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/prependDailyNoteBlock": {+ request: DailyNoteBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/setBlockReminder": {+ request: BlockReminderRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/swapBlockRef": {+ request: SwapBlockRefRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/transferBlockRef": {+ request: TransferBlockRefRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/unfoldBlock": {+ request: BlockIDRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/updateBlock": {+ request: UpdateBlockRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/block/updateTaskListItemMarker": {+ request: TaskListMarkerRequestInput;+ response: { "code": 0; "data": Array<BlockTransaction | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/bookmark/removeBookmark": {request: RemoveBookmarkRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -829,6 +1132,11 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": SearchHistoryData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/notebook/changeMasterPassword": {+ request: ChangeMasterPasswordRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/notebook/changeSortNotebook": {request: ChangeSortNotebookRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -839,16 +1147,66 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/notebook/createEncryptedNotebook": {+ request: CreateEncryptedNotebookRequestInput;+ response: { "code": 0; "data": CreateNotebookData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/notebook/createNotebook": {request: CreateNotebookRequestInput;response: { "code": 0; "data": CreateNotebookData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/notebook/disableEncryptedNotebooks": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };+ "/api/notebook/enableEncryptedNotebooks": {+ request: NotebookPasswordRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/notebook/exportNotebookCryptoBackup": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": NotebookCryptoBackupData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };+ "/api/notebook/getEncryptedNotebookStatus": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": EncryptedNotebookStatusData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };+ "/api/notebook/getNotebookConf": {+ request: CloseNotebookRequestInput;+ response: { "code": 0; "data": NotebookConfData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/notebook/getNotebookInfo": {+ request: NotebookIDRequestInput;+ response: { "code": 0; "data": NotebookInfoData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/notebook/importNotebookCryptoBackup": {+ request: ImportNotebookCryptoBackupRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "multipart";+ };+ "/api/notebook/lockNotebook": {+ request: NotebookIDRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/notebook/lsNotebooks": {request: ListNotebooksRequestInput;response: { "code": 0; "data": ListNotebooksData | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "legacyOptional";};+ "/api/notebook/openNotebook": {+ request: OpenNotebookRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/notebook/removeNotebook": {request: NotebookIDRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -859,11 +1217,41 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/notebook/reorder": {+ request: ReorderNotebooksRequestInput;+ response: { "code": 0; "data": ReorderData | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null | ReorderData | null; "msg": string; };+ body: "structJSON";+ };+ "/api/notebook/setNotebookConf": {+ request: SetNotebookConfRequestInput;+ response: { "code": 0; "data": NotebookConf | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/notebook/setNotebookCryptoAutoLock": {+ request: NotebookCryptoAutoLockRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/notebook/setNotebookIcon": {request: SetNotebookIconRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/notebook/touchEncryptedNotebooks": {+ request: EmptyRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "none";+ };+ "/api/notebook/unlockAndOpenNotebook": {+ request: UnlockNotebookRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/notebook/unlockNotebook": {+ request: UnlockNotebookRequestInput;+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };"/api/repo/checkSnapshot": {request: EmptyRequestInput;response: { "code": 0; "data": CheckSnapshotData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };@@ -1035,7 +1423,12 @@ export interface APILegacyResponse {}type APIContract = {request: unknown; response: unknown; body: string};-type APIRequestArgs<C extends APIContract> = C["body"] extends "json"+export interface APIFormData<Request> extends FormData {+ readonly apiRequest: Request;+}+type APIRequestArgs<C extends APIContract> = C["body"] extends "multipart"+ ? [data: APIFormData<C["request"]>]+ : C["body"] extends "json" | "structJSON"? [data: C["request"]]: [data?: C["request"] | null];type NonNegative<C extends number> = C extends C ? `${C}` extends `-${string}` ? never : C : never;diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex d649def3e3..87b6b83f74 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -5,6 +5,8 @@ type TDock = "file" | "outline" | "inbox" | "bookmark" | "tag" | "graph" | "globtype TTab = "Outline" | "Graph" | "Backlink" | "Asset" | "Editor" | "Search" | "siyuan-card"type TOperation ="insert"+ | "appendInsert"+ | "prependInsert"| "restoreCreatedDoc"| "removeCreatedDoc"| "update"@@ -817,7 +819,7 @@ interface IOperation {viewID?: string // 多个属性视图操作使用,用于推送时不影响其他视图viewIDs?: string[] // setAttrViewColHidden 批量指定数据库视图name?: string // addAttrViewCol 专享- type?: TAVCol // addAttrViewCol 专享+ type?: TAVCol | "" // 非属性视图操作返回空字符串deckID?: string // add/removeFlashcards 专享blockIDs?: string[] // add/removeFlashcards 专享removeDest?: boolean // removeAttrViewCol 专享diff --git a/app/src/util/contractFormData.test.ts b/app/src/util/contractFormData.test.tsnew file mode 100644index 0000000000..dc4c049aa9--- /dev/null+++ b/app/src/util/contractFormData.test.ts@@ -0,0 +1,13 @@+import * as assert from "node:assert/strict";+import {test} from "node:test";+import {ContractFormData} from "./contractFormData";++test("serializes typed upload fields without trimming passwords or adding omitted values", async () => {+ const data = new ContractFormData({file: new Blob(["backup"]), password: " secret ", omitted: undefined});+ assert.equal(data.get("password"), " secret ");+ assert.equal(data.has("omitted"), false);+ const file = data.get("file");+ assert.ok(file instanceof Blob);+ assert.equal(await file.text(), "backup");+ assert.ok(data instanceof FormData);+});diff --git a/app/src/util/contractFormData.ts b/app/src/util/contractFormData.tsnew file mode 100644index 0000000000..4445a172ba--- /dev/null+++ b/app/src/util/contractFormData.ts@@ -0,0 +1,16 @@+import type {APIFormData} from "../types/api";++// 从类型化字段构造上传表单,保留文件名和可缺省字段。+export class ContractFormData<Request extends Record<string, string | Blob | undefined>> extends FormData implements APIFormData<Request> {+ public readonly apiRequest: Request;++ constructor(request: Request) {+ super();+ this.apiRequest = request;+ Object.entries(request).forEach(([name, value]) => {+ if (value !== undefined) {+ this.append(name, value);+ }+ });+ }+}diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.tsindex 4461354bb7..d9750403d8 100644--- a/app/src/util/reloadSync.ts+++ b/app/src/util/reloadSync.ts@@ -1,3 +1,4 @@+import type {BlockQueryRequestInput} from "../types/api";import type {App} from "../index";import {hideMessage} from "../dialog/message";import {hideElements} from "../protyle/ui/hideElements";@@ -50,7 +51,7 @@ export const reloadSync = (}} else {window.siyuan.mobile.editor.reload(false, updateReadonly);- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: window.siyuan.mobile.editor.protyle.block.rootID};if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {@@ -74,7 +75,7 @@ export const reloadSync = (removeBlockPanelEditors({rootIDs: data.removeRootIDs});const allModels = getAllModels();const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: rootID};if (protyle && isEncryptedBox(protyle.notebookId)) {@@ -90,7 +91,7 @@ export const reloadSync = (};allModels.editor.forEach(item => {if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {- const docInfoParam: IObject = {+ const docInfoParam: BlockQueryRequestInput = {id: item.editor.protyle.block.rootID,};if (isEncryptedBox(item.editor.protyle.notebookId)) {diff --git a/app/tests/api-contract.types.ts b/app/tests/api-contract.types.tsindex 58a4491e6c..b95579fe20 100644--- a/app/tests/api-contract.types.ts+++ b/app/tests/api-contract.types.ts@@ -1,10 +1,19 @@import type {APIPOSTRoutes, FetchGet, FetchPost, FetchSyncPost} from "../src/types/api";+import {ContractFormData} from "../src/util/contractFormData";declare const fetchPost: FetchPost;declare const fetchGet: FetchGet;declare const fetchSyncPost: FetchSyncPost;declare const dynamicURL: string;+fetchSyncPost("/api/notebook/importNotebookCryptoBackup", new ContractFormData({file: new Blob(), password: "password"}));+// @ts-expect-error 上传请求必须包含文件。+fetchSyncPost("/api/notebook/importNotebookCryptoBackup", new ContractFormData({password: "password"}));+// @ts-expect-error 文件字段不能使用字符串。+fetchSyncPost("/api/notebook/importNotebookCryptoBackup", new ContractFormData({file: "backup.json"}));+// @ts-expect-error 普通表单没有已校验的字段类型。+fetchSyncPost("/api/notebook/importNotebookCryptoBackup", new FormData());+fetchPost("/api/system/version");fetchPost("/api/notebook/lsNotebooks");fetchPost("/api/notebook/lsNotebooks", {flashcard: null});@@ -98,6 +107,19 @@ async function checkAsyncResult() {}void checkAsyncResult;+fetchPost("/api/block/getHeadingDeleteTransaction", {id: "id"}, response => {+ const operation = response.data?.doOperations?.[0];+ if (operation) {+ const data: string | {createEmptyParagraph: boolean} | null = operation.data;+ const result: string | string[] | null = operation.retData;+ // @ts-expect-error 块操作载荷不能退化为任意对象。+ void operation.data.content;+ // @ts-expect-error 返回值也可能是文本或空值,不能直接当作数组。+ const ids: string[] = operation.retData;+ void [data, result, ids];+ }+});+declare const notebooks: APIPOSTRoutes["/api/notebook/lsNotebooks"]["response"];if (notebooks.code === 0) {// @ts-expect-error 成功码下的空数据也必须在严格模式下被检查。diff --git a/docs/API-CONTRACTS.md b/docs/API-CONTRACTS.mdindex 1d1d43c582..2028317743 100644--- a/docs/API-CONTRACTS.md+++ b/docs/API-CONTRACTS.md@@ -20,6 +20,8 @@ Arrays, maps, and nested structs recursively validate request constraints. A `nuNotebook creation, renaming, removal, closing, icon updates, and sorting use typed contracts. Renaming, removal, and icon updates trim notebook IDs; closing preserves whitespace for ID validation. Empty names and icons remain available to business validation, and rename failures retain their message display duration.+Encrypted notebook lifecycle endpoints use typed requests and responses while retaining password trimming, fractional-minute truncation, negative-minute clamping, administrative authorization, lease acquisition, and mount rollback. Key derivation, ciphertext formats, and recovery material remain model-layer responsibilities.+## Compatibility requirementsContract maintenance must preserve existing observable API behavior. Changes to type definitions or handler structure alone must not change call semantics:@@ -38,6 +40,20 @@ Read-only middleware may still return a prompt object containing `closeTimeout`.Use `FailureWithTimeout` when a business error must preserve its message display duration. Contract-based block queries use `holdContractBlockRequest` to retain lease checks for explicit notebooks and accompanying IDs. Individual entry points still specify whether state queries permit deleted IDs.+`StructJSONBody` is reserved for endpoints that already use Go JSON struct binding. It preserves case-insensitive field matching, null handling, and parser errors; required business fields are validated by the handler. It must not be used to relax a migrated endpoint's request rules. Endpoints that return their result payload on failure explicitly set `DataOnError` and use the endpoint's typed `FailureWithData` method.++Notebook configuration updates use a typed partial object. The `legacyobject` field option preserves the existing JSON round-trip's numeric normalization and case-insensitive struct binding; optional pointer fields leave existing values unchanged when omitted or null. Encryption fields are decoded for input compatibility but never applied by the configuration patch. `Base64Bytes` explicitly models historical byte-slice inputs as Base64 strings or byte arrays.++`JSONValue` is reserved for fields whose wire protocol explicitly accepts arbitrary JSON, such as an echoed correlation ID. Its schema is a recursive union of null, booleans, numbers, strings, arrays, and objects; it does not stand in for a structured request or response. Word-count results retain their fixed statistics fields independently of the correlation value.++Heading transaction queries return `BlockTransaction` with typed operations and preserve empty, null, and undo-operation payloads. `BlockOperationResult` declares the finite union of text, block ID arrays, and null. Conversion from the model's polymorphic fields rejects unsupported types; attribute-view operations require their own payload contracts. The editor's operation type also accepts the empty column-type field returned by non-attribute-view operations.++## Multipart requests++Use `MultipartBody` for file uploads. Request structs declare string fields and `*multipart.FileHeader` fields using their wire names; file schemas use `type: string` and `format: binary`, generating `Blob` declarations. The adapter retains Gin multipart parsing and binds the first value for repeated fields. File contents remain available through `Open`, so handlers preserve their read and recovery logic. Unsupported field types and binding options fail generation.++Frontend callers construct `ContractFormData` from typed fields before passing it to the existing fetch functions. The generated signatures require the endpoint's fields and distinguish file values from strings; raw `FormData` cannot satisfy a migrated upload contract. Optional fields are omitted and string values are not trimmed. Plugin callers can implement the generated `APIFormData<Request>` interface when constructing their forms.+## Endpoint maintenance1. Define or update transport types and endpoints in the contract package, specifying request bodies, error codes, null values, defaults, and historical input compatibilitydiff --git a/docs/API-CONTRACTS.zh-CN.md b/docs/API-CONTRACTS.zh-CN.mdindex 71a86a2850..448c58952c 100644--- a/docs/API-CONTRACTS.zh-CN.md+++ b/docs/API-CONTRACTS.zh-CN.md@@ -20,6 +20,8 @@笔记本创建、重命名、删除、关闭、图标更新和排序已接入类型契约。重命名、删除和图标更新会去除笔记本 ID 两端空白;关闭保留空白并交给 ID 校验。空名称和空图标仍交给业务层处理,重命名失败保留提示显示时长。+加密笔记本生命周期接口使用类型化请求与响应,保留密码去除两端空白、分钟数截断与负值归零、管理员权限、租约获取和挂载失败回滚。密钥派生、密文格式及恢复材料仍由模型层维护。+## 兼容要求契约维护必须保留接口已有的可观察行为,不能仅因类型定义或处理函数重构而改变调用语义:@@ -38,6 +40,20 @@业务错误需要保留提示显示时长时使用 `FailureWithTimeout`。使用契约的块查询通过 `holdContractBlockRequest` 保留显式笔记本及附带 ID 的租约检查;状态查询允许已删除 ID 的行为仍由对应入口明确指定。+`StructJSONBody` 用于已经采用 Go JSON 结构体绑定的接口,保留字段名大小写兼容、空值处理和解析错误,业务必填字段继续由处理函数校验。不得用它放宽已迁移接口的请求规则。失败时仍返回业务结果的端点显式设置 `DataOnError`,并调用端点自身的类型化 `FailureWithData` 方法。++笔记本配置更新使用类型化的部分对象。字段选项 `legacyobject` 保留既有 JSON 往返转换中的数字归一化和结构体字段名大小写兼容;可缺省指针字段在缺失或为 null 时保留原值。加密字段仅为输入兼容而解码,配置补丁不会应用这些字段。`Base64Bytes` 显式描述字节切片的 Base64 字符串或字节数组输入。++`JSONValue` 仅用于线协议明确接受任意 JSON 的字段,例如原样返回的请求标识。其 schema 是 null、布尔、数字、字符串、数组和对象的递归联合,不可代替应有明确结构的请求或响应。字数统计结果的固定字段与请求标识分别建模。++标题事务查询使用 `BlockTransaction` 返回有类型的操作,保留空数组、空值和撤销操作载荷。`BlockOperationResult` 明确声明文本、块 ID 数组和空值的有限联合类型。业务模型中的多态字段转换时拒绝不支持的类型,属性视图操作需要单独声明其载荷契约。编辑器操作类型同时接受非属性视图操作返回的空列类型字段。++## 文件上传请求++文件上传使用 `MultipartBody`。请求结构体以线协议字段名声明字符串和 `*multipart.FileHeader` 字段;文件 schema 使用 `type: string` 与 `format: binary`,生成 `Blob` 类型。适配器保留 Gin 的表单解析方式,重复字段取首值;文件内容继续通过 `Open` 读取,处理函数保留读取及恢复逻辑。未支持的字段类型和绑定选项会使生成失败。++前端从类型化字段构造 `ContractFormData`,再交给现有请求函数。生成签名检查端点所需字段并区分文件与字符串,普通 `FormData` 不能满足已迁移上传接口的契约。可缺省字段不写入表单,字符串不裁剪空白。插件调用方构造表单时可实现生成的 `APIFormData<Request>` 接口。+## 接口维护流程1. 在契约包中定义或更新传输类型与端点,明确请求体、错误码、空值、默认值和历史输入兼容规则diff --git a/kernel/api/block.go b/kernel/api/block.goindex 5b9df70235..8b9ff80a71 100644--- a/kernel/api/block.go+++ b/kernel/api/block.go@@ -205,28 +205,14 @@ func parseBlockRefStringArray(arg map[string]any, key string, ret *gulu.Result,return values, true}-func getBlockTreeInfos(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var ids []string- idsArg := arg["ids"].([]any)- for _, id := range idsArg {- ids = append(ids, id.(string))- }-- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+var getBlockTreeInfos = contractHandler(apicontract.GetBlockTreeInfos, func(c *gin.Context, request apicontract.BlocksQueryRequest) apicontract.Response[map[string]*apicontract.BlockTreeInfo] {+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[map[string]*apicontract.BlockTreeInfo](-1, err.Error())}- ids = filterBlockIDsByPublishAccess(c, ids, boxID)- ret.Data = model.GetBlockTreeInfosInBox(ids, boxID)-}+ ids := filterBlockIDsByPublishAccess(c, request.IDs, boxID)+ return apicontract.Success(blockTreeInfoContracts(model.GetBlockTreeInfosInBox(ids, boxID)))+})var getBlockSiblingID = contractHandler(apicontract.GetBlockSiblingID, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.BlockSiblingData] {boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)@@ -255,69 +241,28 @@ var getBlockRelevantIDs = contractHandler(apicontract.GetBlockRelevantIDs, func(return apicontract.Success(apicontract.BlockRelevantData{ParentID: parent, PreviousID: previous, NextID: next})})-func transferBlockRef(c *gin.Context) {+var transferBlockRef = contractHandler(apicontract.TransferBlockRef, func(c *gin.Context, request apicontract.TransferBlockRefRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- fromID := arg["fromID"].(string)- if util.InvalidIDPattern(fromID, ret) {- return- }- toID := arg["toID"].(string)- if util.InvalidIDPattern(toID, ret) {- return- }-- reloadUI := true- if nil != arg["reloadUI"] {- reloadUI = arg["reloadUI"].(bool)+ if util.InvalidIDPattern(request.FromID, ret) || util.InvalidIDPattern(request.ToID, ret) {+ return contractFailure[apicontract.Null](ret)}-var refIDs []string- if nil != arg["refIDs"] {- for _, refID := range arg["refIDs"].([]any) {- refIDs = append(refIDs, refID.(string))- }- }-- err := model.TransferBlockRef(fromID, toID, refIDs)- if err != nil {- ret.Code = -1- ret.Msg = err.Error()- ret.Data = map[string]any{"closeTimeout": 7000}- return+ refIDs = append(refIDs, request.RefIDs...)+ if err := model.TransferBlockRef(request.FromID, request.ToID, refIDs); err != nil {+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 7000)}-- if reloadUI {+ if request.ReloadUI == nil || *request.ReloadUI {util.ReloadUI()}-}--func swapBlockRef(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return apicontract.Success(apicontract.Null{})+})- refID := arg["refID"].(string)- defID := arg["defID"].(string)- includeChildren := arg["includeChildren"].(bool)- err := model.SwapBlockRef(refID, defID, includeChildren)- if err != nil {- ret.Code = -1- ret.Msg = err.Error()- ret.Data = map[string]any{"closeTimeout": 7000}- return+var swapBlockRef = contractHandler(apicontract.SwapBlockRef, func(c *gin.Context, request apicontract.SwapBlockRefRequest) apicontract.Response[apicontract.Null] {+ if err := model.SwapBlockRef(request.RefID, request.DefID, request.IncludeChildren); err != nil {+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 7000)}-}+ return apicontract.Success(apicontract.Null{})+})var getHeadingChildrenIDs = contractHandler(apicontract.GetHeadingChildrenIDs, func(c *gin.Context, request apicontract.BlockIDRequest) apicontract.Response[[]string] {ret := gulu.Ret.NewResult()@@ -344,49 +289,27 @@ var getHeadingChildrenDOM = contractHandler(apicontract.GetHeadingChildrenDOM, freturn apicontract.Success(model.GetHeadingChildrenDOM(request.ID, removeFoldAttr))})-func getHeadingDeleteTransaction(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)+var getHeadingDeleteTransaction = contractHandler(apicontract.GetHeadingDeleteTransaction, func(c *gin.Context, request apicontract.BlockIDRequest) apicontract.Response[*apicontract.BlockTransaction] {+ id := request.IDtransaction, err := model.GetHeadingDeleteTransaction(id)if err != nil {- ret.Code = -1- ret.Msg = err.Error()- ret.Data = map[string]any{"closeTimeout": 7000}- return+ return apicontract.FailureWithTimeout[*apicontract.BlockTransaction](-1, err.Error(), 7000)}- ret.Data = transaction-}--func getHeadingInsertTransaction(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return blockTransactionResponse(transaction)+})- id := arg["id"].(string)+var getHeadingInsertTransaction = contractHandler(apicontract.GetHeadingInsertTransaction, func(c *gin.Context, request apicontract.BlockIDRequest) apicontract.Response[*apicontract.BlockTransaction] {+ id := request.IDtransaction, err := model.GetHeadingInsertTransaction(id)if err != nil {- ret.Code = -1- ret.Msg = err.Error()- ret.Data = map[string]any{"closeTimeout": 7000}- return+ return apicontract.FailureWithTimeout[*apicontract.BlockTransaction](-1, err.Error(), 7000)}- ret.Data = transaction-}+ return blockTransactionResponse(transaction)+})func getDocHeadingLevelTransaction(c *gin.Context) {ret := gulu.Ret.NewResult()@@ -446,47 +369,24 @@ func getHeadingLevelTransaction(c *gin.Context) {ret.Data = transaction}-func getHeadingFoldTransaction(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+var getHeadingFoldTransaction = contractHandler(apicontract.GetHeadingFoldTransaction, func(c *gin.Context, request apicontract.HeadingFoldRequest) apicontract.Response[*apicontract.BlockTransaction] {+ id := request.ID+ scope := request.Scope- id := arg["id"].(string)- scope := arg["scope"].(string)transaction, err := model.GetHeadingFoldTransaction(id, scope)if err != nil {- ret.Code = -1- ret.Msg = err.Error()- ret.Data = map[string]any{"closeTimeout": 7000}- return+ return apicontract.FailureWithTimeout[*apicontract.BlockTransaction](-1, err.Error(), 7000)}- ret.Data = transaction-}--func setBlockReminder(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return blockTransactionResponse(transaction)+})- id := arg["id"].(string)- timed := arg["timed"].(string) // yyyyMMddHHmmss- err := model.SetBlockReminder(id, timed)- if err != nil {- ret.Code = -1- ret.Msg = err.Error()- ret.Data = map[string]any{"closeTimeout": 7000}- return+var setBlockReminder = contractHandler(apicontract.SetBlockReminder, func(c *gin.Context, request apicontract.BlockReminderRequest) apicontract.Response[apicontract.Null] {+ if err := model.SetBlockReminder(request.ID, request.Timed); err != nil {+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 7000)}-}+ return apicontract.Success(apicontract.Null{})+})func setCloudReminder(c *gin.Context) {ret := gulu.Ret.NewResult()@@ -543,46 +443,34 @@ var checkBlockExist = contractHandler(apicontract.CheckBlockExist, func(c *gin.Creturn apicontract.Success(treenode.ExistBlockTree(request.ID))})-func checkBlocksExist(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- idsArg := arg["ids"].([]any)- var ids []string- for _, idArg := range idsArg {- if id, idOk := idArg.(string); idOk && ast.IsNodeIDPattern(id) {- ids = append(ids, id)+var checkBlocksExist = contractHandler(apicontract.CheckBlocksExist, func(c *gin.Context, request apicontract.CheckBlocksExistRequest) apicontract.Response[map[string]bool] {+ var ids, leaseIDs []string+ for _, value := range request.IDs {+ if id, ok := value.StringValue(); ok {+ leaseIDs = append(leaseIDs, id)+ if ast.IsNodeIDPattern(id) {+ ids = append(ids, id)+ }}}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg, true) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, leaseIDs, true)+ if err != nil {+ return apicontract.Failure[map[string]bool](-1, err.Error())}ids = filterBlockIDsByPublishAccess(c, ids, boxID)- ret.Data = treenode.ExistBlockTreesInBox(ids, boxID)-}+ return apicontract.Success(treenode.ExistBlockTreesInBox(ids, boxID))+})-func getDocInfo(c *gin.Context) {+var getDocInfo = contractHandler(apicontract.GetDocInfo, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[*apicontract.DocInfo] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ id := request.ID+ boxID, leaseErr := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if leaseErr != nil {+ return apicontract.Failure[*apicontract.DocInfo](-1, leaseErr.Error())}if !checkBlockPublishAccessInBox(c, id, boxID, ret) {- return+ return contractFailure[*apicontract.DocInfo](ret)}var info *model.BlockInfo@@ -601,24 +489,19 @@ func getDocInfo(c *gin.Context) {} else {ret.Msg = fmt.Sprintf(model.Conf.Language(15), id)}- return+ return contractFailure[*apicontract.DocInfo](ret)}if model.IsReadOnlyRoleContext(c) {publishAccess := model.GetPublishAccess()info = model.FilterBlockInfoByPublishAccess(c, publishAccess, info)}- ret.Data = info-}+ return apicontract.Success(docInfoContract(info))+})-func getDocsInfo(c *gin.Context) {+var getDocsInfo = contractHandler(apicontract.GetDocsInfo, func(c *gin.Context, request apicontract.DocsInfoRequest) apicontract.Response[[]*apicontract.DocInfo] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- idsArg := arg["ids"].([]any)+ idsArg := request.IDsisReadOnlyRole := model.IsReadOnlyRoleContext(c)var publishAccess model.PublishAccessif isReadOnlyRole {@@ -626,31 +509,30 @@ func getDocsInfo(c *gin.Context) {}var ids []stringfor _, id := range idsArg {- idStr := id.(string)+ idStr := idif isReadOnlyRole && !model.CheckBlockIdAccessableByPublishAccess(c, publishAccess, idStr) {continue}ids = append(ids, idStr)}if isReadOnlyRole && 0 < len(idsArg) && len(ids) == 0 {- ret.Data = []*model.BlockInfo{}- return+ return apicontract.Success([]*apicontract.DocInfo{})}- queryRefCount := arg["refCount"].(bool)- queryAv := arg["av"].(bool)+ queryRefCount := request.RefCount+ queryAv := request.AVinfo := model.GetDocsInfo(ids, queryRefCount, queryAv)if nil == info {ret.Code = -1ret.Msg = fmt.Sprintf(model.Conf.Language(15), ids)- return+ return contractFailure[[]*apicontract.DocInfo](ret)}if isReadOnlyRole {for i, docinfo := range info {info[i] = model.FilterBlockInfoByPublishAccess(c, publishAccess, docinfo)}}- ret.Data = info-}+ return apicontract.Success(docInfoContracts(info))+})func getRecentUpdatedBlocks(c *gin.Context) {ret := gulu.Ret.NewResult()@@ -664,76 +546,35 @@ func getRecentUpdatedBlocks(c *gin.Context) {ret.Data = blocks}-func getContentWordCount(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- content := arg["content"].(string)- ret.Data = map[string]any{- "reqId": arg["reqId"],- "stat": filesys.ContentStat(content),- }-}--func getBlocksWordCount(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+var getContentWordCount = contractHandler(apicontract.GetContentWordCount, func(c *gin.Context, request apicontract.ContentWordCountRequest) apicontract.Response[apicontract.WordCountData] {+ return apicontract.Success(apicontract.WordCountData{ReqID: request.ReqID, Stat: blockStatContract(filesys.ContentStat(request.Content))})+})- idsArg := arg["ids"].([]any)- var ids []string- for _, id := range idsArg {- ids = append(ids, id.(string))- }- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg, true) {- return- }- ids = filterBlockIDsByPublishAccess(c, ids, boxID)- ret.Data = map[string]any{- "reqId": arg["reqId"],- "stat": filesys.BlocksWordCount(ids),+var getBlocksWordCount = contractHandler(apicontract.GetBlocksWordCount, func(c *gin.Context, request apicontract.BlocksWordCountRequest) apicontract.Response[apicontract.WordCountData] {+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, true)+ if err != nil {+ return apicontract.Failure[apicontract.WordCountData](-1, err.Error())}-}+ ids := filterBlockIDsByPublishAccess(c, request.IDs, boxID)+ return apicontract.Success(apicontract.WordCountData{ReqID: request.ReqID, Stat: blockStatContract(filesys.BlocksWordCount(ids))})+})-func getTreeStat(c *gin.Context) {+var getTreeStat = contractHandler(apicontract.GetTreeStat, func(c *gin.Context, request apicontract.TreeStatRequest) apicontract.Response[apicontract.TreeStatData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return+ id, includeEmbed := strings.TrimSpace(request.ID), request.IncludeEmbed+ if id == "" {+ return apicontract.Failure[apicontract.TreeStatData](-1, "Field [id] must not be empty")}-- var id string- var includeEmbed bool- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("id", &id, true, true),- util.BindJsonArg("includeEmbed", &includeEmbed, false, false),- ) || util.InvalidIDPattern(id, ret) {- return+ if util.InvalidIDPattern(id, ret) {+ return contractFailure[apicontract.TreeStatData](ret)}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[apicontract.TreeStatData](-1, err.Error())}if !isBlockPublishAccessible(c, id, boxID) {- ret.Data = map[string]any{- "reqId": arg["reqId"],- "stat": nil,- }- return+ return apicontract.Success(apicontract.TreeStatData{ReqID: request.ReqID})}-var accessChecker model.EmbedBlockAccessCheckerif model.IsReadOnlyRoleContext(c) {publishAccess := model.GetPublishAccess()@@ -742,47 +583,26 @@ func getTreeStat(c *gin.Context) {}}stat := model.GetDocumentStat(c.Request.Context(), id, boxID, includeEmbed, accessChecker)- data := map[string]any{- "reqId": arg["reqId"],- "stat": nil,- "containsEmbed": false,- }- if nil != stat {- data["stat"] = stat.Stat- data["containsEmbed"] = stat.ContainsEmbed- if includeEmbed {- data["statWithEmbed"] = stat.StatWithEmbed- data["embedStat"] = stat.EmbedStat- }- }- ret.Data = data-}+ return apicontract.Success(treeStatContract(request.ReqID, stat, includeEmbed))+})var getDOMText = contractHandler(apicontract.GetDOMText, func(c *gin.Context, request apicontract.DOMTextRequest) apicontract.Response[string] {return apicontract.Success(model.GetDOMText(request.DOM))})-func getRefText(c *gin.Context) {+var getRefText = contractHandler(apicontract.GetRefText, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[string] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[string](ret)}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[string](-1, err.Error())}if !isBlockPublishAccessible(c, id, boxID) {- ret.Data = model.ErrBlockNotFound.Error()- return+ return apicontract.Success(model.ErrBlockNotFound.Error())}// 加密笔记本的块引解析走 InBox 版(查加密 blocktree + content db)@@ -795,136 +615,79 @@ func getRefText(c *gin.Context) {if "" == refText {// 空块返回 id https://github.com/siyuan-note/siyuan/issues/10259refText = id- ret.Data = refText- return+ return apicontract.Success(refText)}if strings.Count(refText, "\\") == len(refText) {// 全部都是 \ 的话使用实体 https://github.com/siyuan-note/siyuan/issues/11473refText = strings.ReplaceAll(refText, "\\", "\")- ret.Data = refText- return+ return apicontract.Success(refText)}- ret.Data = refText-}--func getRefIDs(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- if nil == arg["id"] {- arg["id"] = ""- }+ return apicontract.Success(refText)+})- id := arg["id"].(string)- requestedNotebook, _ := arg["notebook"].(string)+var getRefIDs = contractHandler(apicontract.GetRefIDs, func(c *gin.Context, request apicontract.RefIDsRequest) apicontract.Response[apicontract.RefIDsData] {+ id := request.ID+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]any{- "refDefs": []model.RefDefs{},- "originalRefBlockIDs": map[string]string{},- }- return+ return apicontract.Success(apicontract.RefIDsData{RefDefs: []*apicontract.RefDefs{}, OriginalRefBlockIDs: map[string]string{}})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[apicontract.RefIDsData](-1, err.Error())}refDefs, originalRefBlockIDs := model.GetBlockRefsInBox(id, boxID)if model.IsReadOnlyRoleContext(c) {publishAccess := model.GetPublishAccess()refDefs, originalRefBlockIDs = model.FilterRefDefsByPublishAccess(c, publishAccess, refDefs)}- ret.Data = map[string]any{- "refDefs": refDefs,- "originalRefBlockIDs": originalRefBlockIDs,- }-}--func getRefIDsByFileAnnotationID(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return apicontract.Success(apicontract.RefIDsData{RefDefs: refDefContracts(refDefs), OriginalRefBlockIDs: originalRefBlockIDs})+})- id := arg["id"].(string)- boxID, _ := arg["notebook"].(string)+var getRefIDsByFileAnnotationID = contractHandler(apicontract.GetRefIDsByFileAnnotationID, func(c *gin.Context, request apicontract.FileAnnotationRefRequest) apicontract.Response[apicontract.RefDefsData] {+ id := request.ID+ boxID := request.NotebookrefIDs := model.GetBlockRefIDsByFileAnnotationIDInBox(id, boxID)if model.IsReadOnlyRoleContext(c) {refIDs = model.FilterRefIDsByPublishAccess(c, model.GetPublishAccess(), refIDs)}- var retRefDefs []model.RefDefs+ var retRefDefs []apicontract.RefDefsfor _, blockID := range refIDs {- retRefDefs = append(retRefDefs, model.RefDefs{RefID: blockID, DefIDs: []string{}})+ retRefDefs = append(retRefDefs, apicontract.RefDefs{RefID: blockID, DefIDs: []string{}})}if 1 > len(retRefDefs) {- retRefDefs = []model.RefDefs{}- }-- ret.Data = map[string]any{- "refDefs": retRefDefs,+ retRefDefs = []apicontract.RefDefs{}}-}-func getBlockDefIDsByRefText(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return apicontract.Success(apicontract.RefDefsData{RefDefs: retRefDefs})+})- anchor := arg["anchor"].(string)- boxID, _ := arg["notebook"].(string)+var getBlockDefIDsByRefText = contractHandler(apicontract.GetBlockDefIDsByRefText, func(c *gin.Context, request apicontract.RefTextQueryRequest) apicontract.Response[apicontract.RefDefsData] {+ anchor := request.Anchor+ boxID := request.Notebookids := model.GetBlockDefIDsByRefTextInBox(anchor, boxID)ids = filterBlockIDsByPublishAccess(c, ids, "")- var retRefDefs []model.RefDefs+ var retRefDefs []apicontract.RefDefsfor _, id := range ids {- retRefDefs = append(retRefDefs, model.RefDefs{RefID: id, DefIDs: []string{}})+ retRefDefs = append(retRefDefs, apicontract.RefDefs{RefID: id, DefIDs: []string{}})}if 1 > len(retRefDefs) {- retRefDefs = []model.RefDefs{}+ retRefDefs = []apicontract.RefDefs{}}- ret.Data = map[string]any{- "refDefs": retRefDefs,- }-}+ return apicontract.Success(apicontract.RefDefsData{RefDefs: retRefDefs})+})-func getBlockBreadcrumb(c *gin.Context) {+var getBlockBreadcrumb = contractHandler(apicontract.GetBlockBreadcrumb, func(c *gin.Context, request apicontract.BlockBreadcrumbRequest) apicontract.Response[[]*apicontract.BlockPath] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)- excludeTypesArg := arg["excludeTypes"]- var excludeTypes []string- if nil != excludeTypesArg {- for _, excludeType := range excludeTypesArg.([]any) {- excludeTypes = append(excludeTypes, excludeType.(string))- }- }-- boxID, _ := arg["notebook"].(string)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ id, excludeTypes := request.ID, request.ExcludeTypes+ boxID := request.Notebook+ if err := holdEncryptedBlockRequests(c, boxID, append([]string{request.ID}, request.IDs...), false); err != nil {+ return apicontract.Failure[[]*apicontract.BlockPath](-1, err.Error())}if !isBlockPublishAccessible(c, id, boxID) {- ret.Data = []*model.BlockPath{}- return+ return apicontract.Success([]*apicontract.BlockPath{})}var blockPath []*model.BlockPath@@ -937,58 +700,44 @@ func getBlockBreadcrumb(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockPath](ret)}- ret.Data = blockPath-}+ return apicontract.Success(blockPathContracts(blockPath))+})-func getBlockBreadcrumbChildren(c *gin.Context) {+var getBlockBreadcrumbChildren = contractHandler(apicontract.GetBlockBreadcrumbChildren, func(c *gin.Context, request apicontract.BlockBreadcrumbChildrenRequest) apicontract.Response[*apicontract.BlockBreadcrumbChildren] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)+ id, excludeTypes := request.ID, request.ExcludeTypesif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[*apicontract.BlockBreadcrumbChildren](ret)}-- var excludeTypes []string- if excludeTypesArg := arg["excludeTypes"]; nil != excludeTypesArg {- for _, excludeType := range excludeTypesArg.([]any) {- excludeTypes = append(excludeTypes, excludeType.(string))- }+ offset, limit := 0, 64+ if request.Offset != nil {+ offset = int(*request.Offset)}-- offset := 0- if offsetArg := arg["offset"]; nil != offsetArg {- offset = int(offsetArg.(float64))+ if request.Limit != nil {+ limit = int(*request.Limit)}- limit := 64- if limitArg := arg["limit"]; nil != limitArg {- limit = int(limitArg.(float64))- }- boxID, _ := arg["notebook"].(string)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID := request.Notebook+ if err := holdEncryptedBlockRequests(c, boxID, append([]string{request.ID}, request.IDs...), false); err != nil {+ return apicontract.Failure[*apicontract.BlockBreadcrumbChildren](-1, err.Error())}if !isBlockPublishAccessible(c, id, boxID) {- ret.Data = &model.BlockBreadcrumbChildren{Items: []*model.BlockPath{}}- return+ return apicontract.Success(&apicontract.BlockBreadcrumbChildren{Items: []*apicontract.BlockPath{}})}children, err := model.GetBlockBreadcrumbChildrenInBox(id, excludeTypes, offset, limit, boxID)if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[*apicontract.BlockBreadcrumbChildren](ret)}- ret.Data = children-}+ if children == nil {+ return apicontract.Success[*apicontract.BlockBreadcrumbChildren](nil)+ }+ return apicontract.Success(&apicontract.BlockBreadcrumbChildren{Items: blockPathContracts(children.Items), HasMore: children.HasMore})+})var getBlockIndex = contractHandler(apicontract.GetBlockIndex, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[int] {boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, true)@@ -1191,24 +940,15 @@ func filterBlockIDsByPublishAccess(c *gin.Context, ids []string, boxID string) [return ret}-func getBlockDOM(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)- requestedNotebook, _ := arg["notebook"].(string)+var getBlockDOM = contractHandler(apicontract.GetBlockDOM, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.BlockDOMData] {+ id := request.ID+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]string{"id": id, "dom": ""}- return+ return apicontract.Success(apicontract.BlockDOMData{ID: id})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[apicontract.BlockDOMData](-1, err.Error())}dom := model.GetBlockDOMInBox(id, boxID)@@ -1226,62 +966,36 @@ func getBlockDOM(c *gin.Context) {}}- ret.Data = map[string]string{- "id": id,- "dom": dom,- }-}+ return apicontract.Success(apicontract.BlockDOMData{ID: id, DOM: dom})+})-func getOrderedListContinueStart(c *gin.Context) {+var getOrderedListContinueStart = contractHandler(apicontract.GetOrderedListContinueStart, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.OrderedListStartData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var id string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) {- return+ id := strings.TrimSpace(request.ID)+ if id == "" {+ return apicontract.Failure[apicontract.OrderedListStartData](-1, "Field [id] must not be empty")}if util.InvalidIDPattern(id, ret) {- return+ return contractFailure[apicontract.OrderedListStartData](ret)}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[apicontract.OrderedListStartData](-1, err.Error())}start, found := model.GetOrderedListContinueStartInBox(id, boxID)- ret.Data = map[string]any{- "start": start,- "found": found,- }-}--func getBlockDOMs(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return apicontract.Success(apicontract.OrderedListStartData{Start: start, Found: found})+})- idsArg := arg["ids"].([]any)- var ids []string- for _, id := range idsArg {- ids = append(ids, id.(string))- }+var getBlockDOMs = contractHandler(apicontract.GetBlockDOMs, func(c *gin.Context, request apicontract.BlocksQueryRequest) apicontract.Response[map[string]string] {+ ids := request.IDs- requestedNotebook, _ := arg["notebook"].(string)+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]string{}- return+ return apicontract.Success(map[string]string{})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[map[string]string](-1, err.Error())}doms := model.GetBlockDOMsInBox(ids, boxID)@@ -1291,27 +1005,18 @@ func getBlockDOMs(c *gin.Context) {filterBlockDOMsByPublishAccess(c, doms, ids, boxID, publishAccess, publishIgnore)}- ret.Data = doms-}--func getBlockDOMWithEmbed(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ return apicontract.Success(doms)+})- id := arg["id"].(string)- requestedNotebook, _ := arg["notebook"].(string)+var getBlockDOMWithEmbed = contractHandler(apicontract.GetBlockDOMWithEmbed, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.BlockDOMData] {+ id := request.ID+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]string{"id": id, "dom": ""}- return+ return apicontract.Success(apicontract.BlockDOMData{ID: id})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[apicontract.BlockDOMData](-1, err.Error())}isReadOnlyRole := model.IsReadOnlyRoleContext(c)var publishAccess model.PublishAccess@@ -1337,35 +1042,19 @@ func getBlockDOMWithEmbed(c *gin.Context) {}}- ret.Data = map[string]string{- "id": id,- "dom": dom,- }-}--func getBlockDOMsWithEmbed(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)+ return apicontract.Success(apicontract.BlockDOMData{ID: id, DOM: dom})+})- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+var getBlockDOMsWithEmbed = contractHandler(apicontract.GetBlockDOMsWithEmbed, func(c *gin.Context, request apicontract.BlocksQueryRequest) apicontract.Response[map[string]string] {+ ids := request.IDs- idsArg := arg["ids"].([]any)- var ids []string- for _, id := range idsArg {- ids = append(ids, id.(string))- }-- requestedNotebook, _ := arg["notebook"].(string)+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]string{}- return+ return apicontract.Success(map[string]string{})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[map[string]string](-1, err.Error())}isReadOnlyRole := model.IsReadOnlyRoleContext(c)var publishAccess model.PublishAccess@@ -1383,8 +1072,8 @@ func getBlockDOMsWithEmbed(c *gin.Context) {filterBlockDOMsByPublishAccess(c, doms, ids, boxID, publishAccess, publishIgnore)}- ret.Data = doms-}+ return apicontract.Success(doms)+})func encryptedNotebookFromArg(arg map[string]any) string {notebook, _ := arg["notebook"].(string)@@ -1437,41 +1126,33 @@ func filterBlockDOMsByPublishAccess(c *gin.Context, doms map[string]string, ids}}-func getBlockKramdown(c *gin.Context) {+var getBlockKramdown = contractHandler(apicontract.GetBlockKramdown, func(c *gin.Context, request apicontract.BlockKramdownRequest) apicontract.Response[apicontract.BlockKramdownData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[apicontract.BlockKramdownData](ret)}// md:Markdown 标记符模式,使用标记符导出// textmark:文本标记模式,使用 span 标签导出// https://github.com/siyuan-note/siyuan/issues/13183mode := "md"- if modeArg := arg["mode"]; nil != modeArg {- mode = modeArg.(string)+ if request.Mode != nil {+ mode = *request.Modeif "md" != mode && "textmark" != mode {ret.Code = -1ret.Msg = "Invalid mode"- return+ return contractFailure[apicontract.BlockKramdownData](ret)}}- requestedNotebook, _ := arg["notebook"].(string)+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]string{"id": id, "kramdown": ""}- return+ return apicontract.Success(apicontract.BlockKramdownData{ID: id})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[apicontract.BlockKramdownData](-1, err.Error())}var kramdown stringif boxID != "" {@@ -1494,28 +1175,15 @@ func getBlockKramdown(c *gin.Context) {}}- ret.Data = map[string]string{- "id": id,- "kramdown": kramdown,- }-}+ return apicontract.Success(apicontract.BlockKramdownData{ID: id, Kramdown: kramdown})+})-func getBlockKramdowns(c *gin.Context) {+var getBlockKramdowns = contractHandler(apicontract.GetBlockKramdowns, func(c *gin.Context, request apicontract.BlocksKramdownRequest) apicontract.Response[map[string]string] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- idsArg := arg["ids"].([]any)var ids []string- for _, id := range idsArg {- idStr := id.(string)- // 验证 ID 格式,跳过无效的 ID- if !util.InvalidIDPattern(idStr, nil) {- ids = append(ids, idStr)+ for _, id := range request.IDs {+ if !util.InvalidIDPattern(id, nil) {+ ids = append(ids, id)}}@@ -1523,23 +1191,22 @@ func getBlockKramdowns(c *gin.Context) {// textmark:文本标记模式,使用 span 标签导出// https://github.com/siyuan-note/siyuan/issues/13183mode := "md"- if modeArg := arg["mode"]; nil != modeArg {- mode = modeArg.(string)+ if request.Mode != nil {+ mode = *request.Modeif "md" != mode && "textmark" != mode {ret.Code = -1ret.Msg = "Invalid mode"- return+ return contractFailure[map[string]string](ret)}}- requestedNotebook, _ := arg["notebook"].(string)+ requestedNotebook := request.Notebookif isEncryptedNotebookDeniedForPublish(c, requestedNotebook) {- ret.Data = map[string]string{}- return+ return apicontract.Success(map[string]string{})}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[map[string]string](-1, err.Error())}var kramdowns map[string]stringif boxID != "" {@@ -1554,8 +1221,8 @@ func getBlockKramdowns(c *gin.Context) {filterBlockKramdownsByPublishAccess(c, kramdowns, ids, boxID, publishAccess, publishIgnore)}- ret.Data = kramdowns-}+ return apicontract.Success(kramdowns)+})func filterBlockKramdownsByPublishAccess(c *gin.Context, kramdowns map[string]string, ids []string, boxID string, publishAccess model.PublishAccess, publishIgnore model.PublishAccess) {for _, id := range ids {@@ -1574,53 +1241,149 @@ func filterBlockKramdownsByPublishAccess(c *gin.Context, kramdowns map[string]st}}-func getChildBlocks(c *gin.Context) {+var getChildBlocks = contractHandler(apicontract.GetChildBlocks, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[[]*apicontract.ChildBlock] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)+ id := request.ID+ if util.InvalidIDPattern(id, ret) {+ return contractFailure[[]*apicontract.ChildBlock](ret)+ }- arg, ok := util.JsonArg(c, ret)- if !ok {- return+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[[]*apicontract.ChildBlock](-1, err.Error())}+ return apicontract.Success(childBlockContracts(model.GetChildBlocksInBox(id, boxID)))+})- id := arg["id"].(string)+var getTailChildBlocks = contractHandler(apicontract.GetTailChildBlocks, func(c *gin.Context, request apicontract.TailChildBlocksRequest) apicontract.Response[[]*apicontract.ChildBlock] {+ ret := gulu.Ret.NewResult()+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[[]*apicontract.ChildBlock](ret)}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+ var n int+ if request.N != nil {+ n = int(*request.N)+ }+ if 1 > n {+ n = 7}- ret.Data = model.GetChildBlocksInBox(id, boxID)++ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)+ if err != nil {+ return apicontract.Failure[[]*apicontract.ChildBlock](-1, err.Error())+ }+ return apicontract.Success(childBlockContracts(model.GetTailChildBlocksInBox(id, n, boxID)))+})++func blockStatContract(stat *util.BlockStatResult) *apicontract.BlockStat {+ if stat == nil {+ return nil+ }+ return &apicontract.BlockStat{RuneCount: stat.RuneCount, WordCount: stat.WordCount, LinkCount: stat.LinkCount,+ ImageCount: stat.ImageCount, RefCount: stat.RefCount, BlockCount: stat.BlockCount}}-func getTailChildBlocks(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)+func childBlockContracts(blocks []*model.ChildBlock) []*apicontract.ChildBlock {+ if blocks == nil {+ return nil+ }+ result := make([]*apicontract.ChildBlock, len(blocks))+ for i, block := range blocks {+ if block != nil {+ result[i] = &apicontract.ChildBlock{ID: block.ID, Type: block.Type, SubType: block.SubType, Content: block.Content, Markdown: block.Markdown}+ }+ }+ return result+}- arg, ok := util.JsonArg(c, ret)- if !ok {- return+func refDefContracts(values []*model.RefDefs) []*apicontract.RefDefs {+ if values == nil {+ return nil+ }+ result := make([]*apicontract.RefDefs, len(values))+ for i, value := range values {+ if value != nil {+ result[i] = &apicontract.RefDefs{RefID: value.RefID, DefIDs: value.DefIDs}+ }}+ return result+}- id := arg["id"].(string)- if util.InvalidIDPattern(id, ret) {- return+func blockTreeInfoContracts(values map[string]*model.BlockTreeInfo) map[string]*apicontract.BlockTreeInfo {+ if values == nil {+ return nil+ }+ result := make(map[string]*apicontract.BlockTreeInfo, len(values))+ for id, value := range values {+ if value == nil {+ result[id] = nil+ } else {+ converted := apicontract.BlockTreeInfo(*value)+ result[id] = &converted+ }}+ return result+}- var n int- nArg := arg["n"]- if nil != nArg {- n = int(nArg.(float64))+func blockPathContracts(values []*model.BlockPath) []*apicontract.BlockPath {+ if values == nil {+ return nil}- if 1 > n {- n = 7+ result := make([]*apicontract.BlockPath, len(values))+ for i, value := range values {+ if value != nil {+ result[i] = &apicontract.BlockPath{ID: value.ID, Name: value.Name, Type: value.Type, SubType: value.SubType, Children: blockPathContracts(value.Children), HasChildren: value.HasChildren}+ }}+ return result+}- boxID := encryptedNotebookFromArg(arg)- if !holdBlockRequest(c, ret, boxID, arg) {- return+func docInfoContract(info *model.BlockInfo) *apicontract.DocInfo {+ if info == nil {+ return nil+ }+ var views []*apicontract.DocAttrView+ if info.AttrViews != nil {+ views = make([]*apicontract.DocAttrView, len(info.AttrViews))+ for i, value := range info.AttrViews {+ if value != nil {+ converted := apicontract.DocAttrView(*value)+ views[i] = &converted+ }+ }+ }+ return &apicontract.DocInfo{ID: info.ID, RootID: info.RootID, Name: info.Name, RefCount: info.RefCount, SubFileCount: info.SubFileCount, RefIDs: info.RefIDs, IAL: info.IAL, Icon: info.Icon, AttrViews: views}+}++func docInfoContracts(values []*model.BlockInfo) []*apicontract.DocInfo {+ if values == nil {+ return nil}- ret.Data = model.GetTailChildBlocksInBox(id, n, boxID)+ ret := make([]*apicontract.DocInfo, len(values))+ for i, value := range values {+ ret[i] = docInfoContract(value)+ }+ return ret+}++func treeStatContract(reqID apicontract.JSONValue, stat *model.DocumentStat, includeEmbed bool) apicontract.TreeStatData {+ containsEmbed := false+ ret := apicontract.TreeStatData{ReqID: reqID, ContainsEmbed: &containsEmbed}+ if stat != nil {+ ret.Stat = blockStatContract(stat.Stat)+ containsEmbed = stat.ContainsEmbed+ if includeEmbed {+ withEmbed := blockStatContract(stat.StatWithEmbed)+ ret.StatWithEmbed = &withEmbed+ var embed *apicontract.EmbedStat+ if stat.EmbedStat != nil {+ converted := apicontract.EmbedStat(*stat.EmbedStat)+ embed = &converted+ }+ ret.EmbedStat = &embed+ }+ }+ return ret}diff --git a/kernel/api/block_op.go b/kernel/api/block_op.goindex af55e1565c..1200aaf21f 100644--- a/kernel/api/block_op.go+++ b/kernel/api/block_op.go@@ -19,33 +19,18 @@ package apiimport ("errors""fmt"- "net/http""github.com/88250/gulu""github.com/88250/lute""github.com/88250/lute/ast""github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract""github.com/siyuan-note/siyuan/kernel/filesys""github.com/siyuan-note/siyuan/kernel/model""github.com/siyuan-note/siyuan/kernel/treenode""github.com/siyuan-note/siyuan/kernel/util")-func parseBlockUpdateInput(arg map[string]any, ret *gulu.Result) (input model.BlockUpdateInput, ok bool) {- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("id", &input.ID, true, true),- util.BindJsonArg("data", &input.Data, true, false),- util.BindJsonArg("dataType", &input.DataType, true, true),- util.BindJsonArg("lockType", &input.LockType, false, false),- ) {- return- }- if util.InvalidIDPattern(input.ID, ret) {- return input, false- }- return input, true-}-func buildUpdatedTaskListItemBlockDOM(id, marker string, luteEngine *lute.Lute) (data string, err error) {block, err := model.GetBlock(id, nil)if err != nil {@@ -92,24 +77,12 @@ func buildUpdatedTaskListItemBlockDOM(id, marker string, luteEngine *lute.Lute)return luteEngine.RenderNodeBlockDOM(li), nil}-func updateTaskListItemMarker(c *gin.Context) {+var updateTaskListItemMarker = contractHandler(apicontract.UpdateTaskListItemMarker, func(c *gin.Context, request apicontract.TaskListMarkerRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var id, marker string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("id", &id, true, true),- util.BindJsonArg("marker", &marker, true, false),- ) {- return- }+ id, marker := request.ID, request.Markerif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}luteEngine := util.NewLute()@@ -117,7 +90,7 @@ func updateTaskListItemMarker(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}transactions := []*model.Transaction{@@ -131,43 +104,24 @@ func updateTaskListItemMarker(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func batchUpdateTaskListItemMarker(c *gin.Context) {+var batchUpdateTaskListItemMarker = contractHandler(apicontract.BatchUpdateTaskListItemMarker, func(c *gin.Context, request apicontract.BatchTaskListMarkerRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- var itemsArg []any- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("items", &itemsArg, true, true)) {- return+ itemsArg := request.Items+ if len(itemsArg) == 0 {+ return apicontract.Failure[[]*apicontract.BlockTransaction](-1, "Field [items] must not be empty")}-luteEngine := util.NewLute()idToMarker := make(map[string]string, len(itemsArg))idsInOrder := make([]string, 0, len(itemsArg))for _, itemArg := range itemsArg {- itemMap, ok := itemArg.(map[string]any)- if !ok {- ret.Code = -1- ret.Msg = "invalid item: each item must be an object"- return- }- var id, marker string- if !util.ParseJsonArgs(itemMap, ret,- util.BindJsonArg("id", &id, true, true),- util.BindJsonArg("marker", &marker, true, false),- ) {- return- }+ id, marker := itemArg.ID, itemArg.Markerif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}// 相同 id 保留最后一个 markeridToMarker[id] = marker@@ -181,7 +135,7 @@ func batchUpdateTaskListItemMarker(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}ops = append(ops, &model.Operation{Action: "update", ID: id, Data: data})@@ -193,35 +147,29 @@ func batchUpdateTaskListItemMarker(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func moveOutlineHeading(c *gin.Context) {+var moveOutlineHeading = contractHandler(apicontract.MoveOutlineHeading, func(c *gin.Context, request apicontract.MoveBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- id := arg["id"].(string)+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}var parentID, previousID string- if nil != arg["parentID"] {- parentID = arg["parentID"].(string)+ if request.ParentID != nil {+ parentID = *request.ParentIDif "" != parentID && util.InvalidIDPattern(parentID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}- if nil != arg["previousID"] {- previousID = arg["previousID"].(string)+ if request.PreviousID != nil {+ previousID = *request.PreviousIDif "" != previousID && util.InvalidIDPattern(previousID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -241,24 +189,16 @@ func moveOutlineHeading(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func appendDailyNoteBlock(c *gin.Context) {+var appendDailyNoteBlock = contractHandler(apicontract.AppendDailyNoteBlock, func(c *gin.Context, request apicontract.DailyNoteBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- data := arg["data"].(string)- dataType := arg["dataType"].(string)- boxID := arg["notebook"].(string)+ data, dataType, boxID := request.Data, request.DataType, request.Notebookif util.InvalidIDPattern(boxID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if "markdown" == dataType {luteEngine := util.NewLute()@@ -267,7 +207,7 @@ func appendDailyNoteBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -275,7 +215,7 @@ func appendDailyNoteBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "create daily note failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}parentID := util.GetTreeID(p)@@ -294,24 +234,16 @@ func appendDailyNoteBlock(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func prependDailyNoteBlock(c *gin.Context) {+var prependDailyNoteBlock = contractHandler(apicontract.PrependDailyNoteBlock, func(c *gin.Context, request apicontract.DailyNoteBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- data := arg["data"].(string)- dataType := arg["dataType"].(string)- boxID := arg["notebook"].(string)+ data, dataType, boxID := request.Data, request.DataType, request.Notebookif util.InvalidIDPattern(boxID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if "markdown" == dataType {luteEngine := util.NewLute()@@ -320,7 +252,7 @@ func prependDailyNoteBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -328,7 +260,7 @@ func prependDailyNoteBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "create daily note failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}parentID := util.GetTreeID(p)@@ -347,35 +279,29 @@ func prependDailyNoteBlock(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func unfoldBlock(c *gin.Context) {+var unfoldBlock = contractHandler(apicontract.UnfoldBlock, func(c *gin.Context, request apicontract.BlockIDRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[apicontract.Null](ret)}bt := treenode.GetBlockTree(id)if nil == bt {ret.Code = -1ret.Msg = "block tree not found [id=" + id + "]"- return+ return contractFailure[apicontract.Null](ret)}if bt.Type == "d" {ret.Code = -1ret.Msg = "document can not be unfolded"- return+ return contractFailure[apicontract.Null](ret)}var transactions []*model.Transaction@@ -409,33 +335,28 @@ func unfoldBlock(c *gin.Context) {model.FlushTxQueue()broadcastTransactions(transactions)-}+ return apicontract.Success(apicontract.Null{})+})-func foldBlock(c *gin.Context) {+var foldBlock = contractHandler(apicontract.FoldBlock, func(c *gin.Context, request apicontract.BlockIDRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- id := arg["id"].(string)+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[apicontract.Null](ret)}bt := treenode.GetBlockTree(id)if nil == bt {ret.Code = -1ret.Msg = "block tree not found [id=" + id + "]"- return+ return contractFailure[apicontract.Null](ret)}if bt.Type == "d" {ret.Code = -1ret.Msg = "document can not be folded"- return+ return contractFailure[apicontract.Null](ret)}var transactions []*model.Transaction@@ -469,47 +390,42 @@ func foldBlock(c *gin.Context) {model.FlushTxQueue()broadcastTransactions(transactions)-}+ return apicontract.Success(apicontract.Null{})+})-func moveBlock(c *gin.Context) {+var moveBlock = contractHandler(apicontract.MoveBlock, func(c *gin.Context, request apicontract.MoveBlockRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- id := arg["id"].(string)+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[apicontract.Null](ret)}currentBt := treenode.GetBlockTree(id)if nil == currentBt {ret.Code = -1ret.Msg = "block not found [id=" + id + "]"- return+ return contractFailure[apicontract.Null](ret)}var parentID, previousID string- if nil != arg["parentID"] {- parentID = arg["parentID"].(string)+ if request.ParentID != nil {+ parentID = *request.ParentIDif "" != parentID && util.InvalidIDPattern(parentID, ret) {- return+ return contractFailure[apicontract.Null](ret)}}- if nil != arg["previousID"] {- previousID = arg["previousID"].(string)+ if request.PreviousID != nil {+ previousID = *request.PreviousIDif "" != previousID && util.InvalidIDPattern(previousID, ret) {- return+ return contractFailure[apicontract.Null](ret)}// Check the validity of the API `moveBlock` parameter `previousID` https://github.com/siyuan-note/siyuan/issues/8007if bt := treenode.GetBlockTree(previousID); nil == bt || "d" == bt.Type {ret.Code = -1ret.Msg = "`previousID` can not be the ID of a document"- return+ return contractFailure[apicontract.Null](ret)}}@@ -523,7 +439,7 @@ func moveBlock(c *gin.Context) {if nil == targetBt {ret.Code = -1ret.Msg = "target block not found [id=" + parentID + "]"- return+ return contractFailure[apicontract.Null](ret)}// 仅靠 parentID 定位目标时(无 previousID),目标必须是容器块,否则非法嵌套@@ -531,12 +447,12 @@ func moveBlock(c *gin.Context) {if err := treenode.CheckListItemNesting(parentID, id); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}if err := treenode.CheckContainerParent(parentID); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}}@@ -560,32 +476,20 @@ func moveBlock(c *gin.Context) {if currentBt.RootID != targetBt.RootID {model.ReloadProtyle(targetBt.RootID)}-}+ return apicontract.Success(apicontract.Null{})+})-func appendBlock(c *gin.Context) {+var appendBlock = contractHandler(apicontract.AppendBlock, func(c *gin.Context, request apicontract.AppendBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var data, dataType, parentID string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("data", &data, true, false),- util.BindJsonArg("dataType", &dataType, true, true),- util.BindJsonArg("parentID", &parentID, true, true),- ) {- return- }+ data, dataType, parentID := request.Data, request.DataType, request.ParentIDif dataType != "markdown" && dataType != "dom" {ret.Code = -1ret.Msg = "dataType must be markdown or dom"- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if util.InvalidIDPattern(parentID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if "markdown" == dataType {luteEngine := util.NewLute()@@ -594,7 +498,7 @@ func appendBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -606,38 +510,31 @@ func appendBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func batchAppendBlock(c *gin.Context) {+var batchAppendBlock = contractHandler(apicontract.BatchAppendBlock, func(c *gin.Context, request apicontract.BatchParentBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- blocksArg := arg["blocks"].([]any)+ blocksArg := request.Blocksvar transactions []*model.TransactionluteEngine := util.NewLute()for _, blockArg := range blocksArg {- blockMap := blockArg.(map[string]any)- data := blockMap["data"].(string)- dataType := blockMap["dataType"].(string)- parentID := blockMap["parentID"].(string)+ data := blockArg.Data+ dataType := blockArg.DataType+ parentID := blockArg.ParentIDif util.InvalidIDPattern(parentID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}// append 只用 parentID 定位目标,目标必须是容器块,否则非法嵌套if err := treenode.CheckContainerParent(parentID); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if "markdown" == dataType {var err error@@ -645,7 +542,7 @@ func batchAppendBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -663,30 +560,22 @@ func batchAppendBlock(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func prependBlock(c *gin.Context) {+var prependBlock = contractHandler(apicontract.PrependBlock, func(c *gin.Context, request apicontract.PrependBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- data := arg["data"].(string)- dataType := arg["dataType"].(string)- parentID := arg["parentID"].(string)+ data, dataType, parentID := request.Data, request.DataType, request.ParentIDif util.InvalidIDPattern(parentID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}// prepend 只用 parentID 定位目标,目标必须是容器块,否则非法嵌套if err := treenode.CheckContainerParent(parentID); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if "markdown" == dataType {luteEngine := util.NewLute()@@ -695,7 +584,7 @@ func prependBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -714,35 +603,28 @@ func prependBlock(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func batchPrependBlock(c *gin.Context) {+var batchPrependBlock = contractHandler(apicontract.BatchPrependBlock, func(c *gin.Context, request apicontract.BatchParentBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- blocksArg := arg["blocks"].([]any)+ blocksArg := request.Blocksvar transactions []*model.TransactionluteEngine := util.NewLute()for _, blockArg := range blocksArg {- blockMap := blockArg.(map[string]any)- data := blockMap["data"].(string)- dataType := blockMap["dataType"].(string)- parentID := blockMap["parentID"].(string)+ data := blockArg.Data+ dataType := blockArg.DataType+ parentID := blockArg.ParentIDif util.InvalidIDPattern(parentID, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}// prepend 只用 parentID 定位目标,目标必须是容器块,否则非法嵌套if err := treenode.CheckContainerParent(parentID); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if "markdown" == dataType {var err error@@ -750,7 +632,7 @@ func batchPrependBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -768,42 +650,27 @@ func batchPrependBlock(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func insertBlock(c *gin.Context) {+var insertBlock = contractHandler(apicontract.InsertBlock, func(c *gin.Context, request apicontract.InsertBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- var data, dataType, parentID, previousID, nextID string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("data", &data, true, false),- util.BindJsonArg("dataType", &dataType, true, true),- util.BindJsonArg("parentID", &parentID, false, false),- util.BindJsonArg("previousID", &previousID, false, false),- util.BindJsonArg("nextID", &nextID, false, false),- ) {- return- }+ data, dataType, parentID, previousID, nextID := request.Data, request.DataType, request.ParentID, request.PreviousID, request.NextIDif dataType != "markdown" && dataType != "dom" {ret.Code = -1ret.Msg = "dataType must be markdown or dom"- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}if parentID == "" && previousID == "" && nextID == "" {ret.Code = -1ret.Msg = "at least one of parentID, previousID or nextID is required"- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}for _, id := range []string{parentID, previousID, nextID} {if id != "" && util.InvalidIDPattern(id, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}if "markdown" == dataType {@@ -813,7 +680,7 @@ func insertBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -827,80 +694,51 @@ func insertBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func updateBlock(c *gin.Context) {+var updateBlock = contractHandler(apicontract.UpdateBlock, func(c *gin.Context, request apicontract.UpdateBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- input, ok := parseBlockUpdateInput(arg, ret)- if !ok {- return+ input := blockUpdateInput(request)+ if util.InvalidIDPattern(input.ID, ret) {+ return contractFailure[[]*apicontract.BlockTransaction](ret)}-transactions, _, err := model.PerformBlockUpdates([]model.BlockUpdateInput{input})if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func batchInsertBlock(c *gin.Context) {+var batchInsertBlock = contractHandler(apicontract.BatchInsertBlock, func(c *gin.Context, request apicontract.BatchInsertBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- blocksArg := arg["blocks"].([]any)+ blocksArg := request.Blocksvar transactions []*model.TransactionluteEngine := util.NewLute()for _, blockArg := range blocksArg {- blockMap := blockArg.(map[string]any)- data := blockMap["data"].(string)- dataType := blockMap["dataType"].(string)- var parentID, previousID, nextID string- if nil != blockMap["parentID"] {- parentID = blockMap["parentID"].(string)- if "" != parentID && util.InvalidIDPattern(parentID, ret) {- return+ data, dataType := blockArg.Data, blockArg.DataType+ parentID, previousID, nextID := blockArg.ParentID, blockArg.PreviousID, blockArg.NextID+ for _, id := range []string{parentID, previousID, nextID} {+ if id != "" && util.InvalidIDPattern(id, ret) {+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}- if nil != blockMap["previousID"] {- previousID = blockMap["previousID"].(string)- if "" != previousID && util.InvalidIDPattern(previousID, ret) {- return- }- }- if nil != blockMap["nextID"] {- nextID = blockMap["nextID"].(string)- if "" != nextID && util.InvalidIDPattern(nextID, ret) {- return- }- }-// 仅靠 parentID 定位目标时(无 previousID/nextID),目标必须是容器块,否则非法嵌套if "" != parentID && "" == previousID && "" == nextID {if err := treenode.CheckContainerParent(parentID); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -910,7 +748,7 @@ func batchInsertBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = "data block DOM failed: " + err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}}@@ -930,66 +768,42 @@ func batchInsertBlock(c *gin.Context) {model.PerformTransactions(&transactions)model.FlushTxQueue()- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func batchUpdateBlock(c *gin.Context) {+var batchUpdateBlock = contractHandler(apicontract.BatchUpdateBlock, func(c *gin.Context, request apicontract.BatchUpdateBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- var blocksArg []any- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("blocks", &blocksArg, true, true)) {- return+ if len(request.Blocks) == 0 {+ return apicontract.Failure[[]*apicontract.BlockTransaction](-1, "Field [blocks] must not be empty")}-- inputs := make([]model.BlockUpdateInput, 0, len(blocksArg))- for i, blockArg := range blocksArg {- blockMap, isMap := blockArg.(map[string]any)- if !isMap {- ret.Code = -1- ret.Msg = fmt.Sprintf("Field [blocks[%d]] should be of type [Object]", i)- return- }- input, parsed := parseBlockUpdateInput(blockMap, ret)- if !parsed {+ inputs := make([]model.BlockUpdateInput, 0, len(request.Blocks))+ for i, block := range request.Blocks {+ input := blockUpdateInput(block)+ if util.InvalidIDPattern(input.ID, ret) {ret.Msg = fmt.Sprintf("blocks[%d]: %s", i, ret.Msg)- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}inputs = append(inputs, input)}-transactions, _, err := model.PerformBlockUpdates(inputs)if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})-func deleteBlock(c *gin.Context) {+var deleteBlock = contractHandler(apicontract.DeleteBlock, func(c *gin.Context, request apicontract.DeleteBlockRequest) apicontract.Response[[]*apicontract.BlockTransaction] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }- var id string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) {- return- }+ id := request.IDif util.InvalidIDPattern(id, ret) {- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}transactions, err := model.PerformBlockOperation(&model.Operation{@@ -999,12 +813,12 @@ func deleteBlock(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[[]*apicontract.BlockTransaction](ret)}- ret.Data = transactionsbroadcastTransactions(transactions)-}+ return blockTransactionsResponse(transactions)+})func broadcastTransactions(transactions []*model.Transaction) {evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast)@@ -1015,3 +829,7 @@ func broadcastTransactions(transactions []*model.Transaction) {func dataBlockDOM(data string, luteEngine *lute.Lute) (ret string, err error) {return model.DataBlockDOM(data, luteEngine)}++func blockUpdateInput(request apicontract.UpdateBlockRequest) model.BlockUpdateInput {+ return model.BlockUpdateInput{ID: request.ID, Data: request.Data, DataType: request.DataType, LockType: request.LockType}+}diff --git a/kernel/api/box_lease_test.go b/kernel/api/box_lease_test.goindex d18045c3ea..8d38281445 100644--- a/kernel/api/box_lease_test.go+++ b/kernel/api/box_lease_test.go@@ -57,6 +57,54 @@ func TestImplicitNotebookResponseLease(t *testing.T) {runNotebookResponseLease(t, false, false)}+func TestContractRefIDsNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, true, false)+}++func TestContractDocInfoNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, true, false)+}++func TestContractTreeStatNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, false)+}++func TestContractBreadcrumbNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, true, false)+}++func TestContractBreadcrumbChildrenNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, false)+}++func TestContractTreeInfosNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, true)+}++func TestContractChildNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, false)+}++func TestContractTailChildNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, true, false)+}++func TestContractDOMNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, false)+}++func TestContractDOMsNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, true)+}++func TestContractEmbedDOMNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, true, false)+}++func TestContractEmbedDOMsNotebookResponseLease(t *testing.T) {+ runNotebookResponseLease(t, false, true)+}+func TestExplicitNotebookResponseLease(t *testing.T) {runNotebookResponseLease(t, true, false)}@@ -153,6 +201,18 @@ func testNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {engine.Use(boxLeaseMiddleware)engine.Use(func(c *gin.Context) { c.Set(model.RoleContextKey, model.RoleAdministrator); c.Next() })engine.POST("/api/block/getBlockKramdown", getBlockKramdown)+ engine.POST("/api/block/getRefIDs", getRefIDs)+ engine.POST("/api/block/getDocInfo", getDocInfo)+ engine.POST("/api/block/getTreeStat", getTreeStat)+ engine.POST("/api/block/getBlockBreadcrumb", getBlockBreadcrumb)+ engine.POST("/api/block/getBlockBreadcrumbChildren", getBlockBreadcrumbChildren)+ engine.POST("/api/block/getBlockTreeInfos", getBlockTreeInfos)+ engine.POST("/api/block/getChildBlocks", getChildBlocks)+ engine.POST("/api/block/getTailChildBlocks", getTailChildBlocks)+ engine.POST("/api/block/getBlockDOM", getBlockDOM)+ engine.POST("/api/block/getBlockDOMs", getBlockDOMs)+ engine.POST("/api/block/getBlockDOMWithEmbed", getBlockDOMWithEmbed)+ engine.POST("/api/block/getBlockDOMsWithEmbed", getBlockDOMsWithEmbed)engine.POST("/api/block/getBlockKramdowns", getBlockKramdowns)engine.POST("/api/block/getBlockInfo", getBlockInfo)engine.POST("/api/block/getBlockSiblingID", getBlockSiblingID)@@ -175,6 +235,31 @@ func testNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {}typedQuery := falseswitch t.Name() {+ case "TestContractDocInfoNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getDocInfo", true+ case "TestContractTreeStatNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getTreeStat", true+ args["includeEmbed"] = true+ case "TestContractBreadcrumbNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getBlockBreadcrumb", true+ case "TestContractBreadcrumbChildrenNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getBlockBreadcrumbChildren", true+ case "TestContractTreeInfosNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getBlockTreeInfos", true+ case "TestContractRefIDsNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getRefIDs", true+ case "TestContractChildNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getChildBlocks", true+ case "TestContractTailChildNotebookResponseLease":+ endpoint, typedQuery = "/api/block/getTailChildBlocks", true+ case "TestContractDOMNotebookResponseLease":+ endpoint = "/api/block/getBlockDOM"+ case "TestContractDOMsNotebookResponseLease":+ endpoint = "/api/block/getBlockDOMs"+ case "TestContractEmbedDOMNotebookResponseLease":+ endpoint = "/api/block/getBlockDOMWithEmbed"+ case "TestContractEmbedDOMsNotebookResponseLease":+ endpoint = "/api/block/getBlockDOMsWithEmbed"case "TestContractSiblingNotebookResponseLease":endpoint, typedQuery = "/api/block/getBlockSiblingID", truecase "TestContractBatchIndexesNotebookResponseLease":diff --git a/kernel/api/contract.go b/kernel/api/contract.goindex be725fad16..b76b7962c7 100644--- a/kernel/api/contract.go+++ b/kernel/api/contract.go@@ -1,20 +1,58 @@package apiimport (+ "encoding/base64""fmt""net/http""github.com/88250/gulu""github.com/gin-gonic/gin""github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/conf""github.com/siyuan-note/siyuan/kernel/model")+func notebookConfContract(value *conf.BoxConf) *apicontract.NotebookConf {+ if value == nil {+ return nil+ }+ result := &apicontract.NotebookConf{+ Name: value.Name, Sort: value.Sort, Icon: value.Icon, Closed: value.Closed,+ RefCreateSaveBox: value.RefCreateSaveBox, RefCreateSavePath: value.RefCreateSavePath,+ DocCreateSaveBox: value.DocCreateSaveBox, DocCreateSavePath: value.DocCreateSavePath,+ DocCreateTemplatePath: value.DocCreateTemplatePath, DailyNoteSavePath: value.DailyNoteSavePath,+ DailyNoteTemplatePath: value.DailyNoteTemplatePath, SortMode: value.SortMode, Encrypted: value.Encrypted,+ }+ if crypt := value.BoxCrypt; crypt != nil {+ encode := func(bytes []byte) *string {+ if bytes == nil {+ return nil+ }+ encoded := base64.StdEncoding.EncodeToString(bytes)+ return &encoded+ }+ result.BoxCrypt = &apicontract.NotebookEncryption{Spec: crypt.Spec, WrappedDEK: encode(crypt.WrappedDEK),+ WrapNonce: encode(crypt.WrapNonce), Metadata: base64.StdEncoding.EncodeToString(crypt.Metadata), CreatedAt: crypt.CreatedAt}+ }+ return result+}+// contractHandler 将请求绑定和响应类型与注册契约关联,业务入口继续使用现有中间件。func contractHandler[Request, Data any](endpoint apicontract.Endpoint[Request, Data],handler func(*gin.Context, Request) apicontract.Response[Data]) gin.HandlerFunc {return func(c *gin.Context) {- request, err := endpoint.Decode(c.Request.Body)+ var request Request+ var err error+ if endpoint.Definition().Body == apicontract.MultipartBody {+ form, parseErr := c.MultipartForm()+ if parseErr != nil {+ err = parseErr+ } else {+ request, err = endpoint.DecodeMultipart(form)+ }+ } else {+ request, err = endpoint.Decode(c.Request.Body)+ }if err != nil {c.JSON(http.StatusOK, apicontract.Failure[Data](-1, err.Error()))return@@ -47,6 +85,16 @@ func notebookContract(box *model.Box) *apicontract.Notebook {}}+func notebookInfoContract(info *model.BoxInfo) *apicontract.NotebookInfo {+ if info == nil {+ return nil+ }+ return &apicontract.NotebookInfo{+ ID: info.ID, Name: info.Name, DocCount: info.DocCount, Size: info.Size, HSize: info.HSize,+ Mtime: info.Mtime, CTime: info.CTime, HMtime: info.HMtime, HCtime: info.HCtime,+ }+}+// holdContractBlockRequest 保留显式笔记本选择及全部附带 ID 的租约检查。func holdContractBlockRequest(c *gin.Context, notebook, id string, ids []string, allowMissing bool) (boxID string, err error) {if notebook != "" && model.IsEncryptedBox(notebook) {diff --git a/kernel/api/contract_basics_test.go b/kernel/api/contract_basics_test.goindex 3f1274714c..1c4f0f4651 100644--- a/kernel/api/contract_basics_test.go+++ b/kernel/api/contract_basics_test.go@@ -17,6 +17,47 @@ func TestAPIContractBasicRequests(t *testing.T) {handler gin.HandlerFunccode int}{+ {"/api/block/foldBlock", `{"id":"invalid"}`, foldBlock, -1},+ {"/api/block/unfoldBlock", `{"id":"invalid"}`, unfoldBlock, -1},+ {"/api/block/moveBlock", `{"id":"invalid"}`, moveBlock, -1},+ {"/api/block/getHeadingDeleteTransaction", `{"id":null}`, getHeadingDeleteTransaction, -1},+ {"/api/block/getHeadingInsertTransaction", `{"id":null}`, getHeadingInsertTransaction, -1},+ {"/api/block/getHeadingFoldTransaction", `{"id":"id","scope":null}`, getHeadingFoldTransaction, -1},+ {"/api/block/transferBlockRef", `{"fromID":"invalid","toID":"invalid"}`, transferBlockRef, -1},+ {"/api/block/swapBlockRef", `{"refID":"id","defID":"id","includeChildren":null}`, swapBlockRef, -1},+ {"/api/block/setBlockReminder", `{"id":"id","timed":null}`, setBlockReminder, -1},+ {"/api/block/getDocInfo", `{"id":null}`, getDocInfo, -1},+ {"/api/block/getDocsInfo", `{"ids":[],"refCount":null,"av":false}`, getDocsInfo, -1},+ {"/api/block/getTreeStat", `{"id":"invalid","includeEmbed":null}`, getTreeStat, -1},+ {"/api/block/getBlockTreeInfos", `{"ids":[null]}`, getBlockTreeInfos, -1},+ {"/api/block/getBlockBreadcrumb", `{"id":"id","excludeTypes":[1]}`, getBlockBreadcrumb, -1},+ {"/api/block/getBlockBreadcrumbChildren", `{"id":"invalid"}`, getBlockBreadcrumbChildren, -1},+ {"/api/block/getRefText", `{"id":"invalid"}`, getRefText, -1},+ {"/api/block/getRefIDs", `{"id":123}`, getRefIDs, -1},+ {"/api/block/getRefIDsByFileAnnotationID", `{"id":null}`, getRefIDsByFileAnnotationID, -1},+ {"/api/block/getBlockDefIDsByRefText", `{"anchor":null}`, getBlockDefIDsByRefText, -1},+ {"/api/block/getChildBlocks", `{"id":"invalid"}`, getChildBlocks, -1},+ {"/api/block/getTailChildBlocks", `{"id":"20260101000000-abcdefg","n":"1"}`, getTailChildBlocks, -1},+ {"/api/block/checkBlocksExist", `{"ids":null}`, checkBlocksExist, -1},+ {"/api/block/getBlocksWordCount", `{"ids":[null]}`, getBlocksWordCount, -1},+ {"/api/block/getOrderedListContinueStart", `{"id":" "}`, getOrderedListContinueStart, -1},+ {"/api/block/getBlockDOM", `{"id":null}`, getBlockDOM, -1},+ {"/api/block/getBlockDOMWithEmbed", `{"id":null}`, getBlockDOMWithEmbed, -1},+ {"/api/block/getBlockDOMs", `{"ids":[null]}`, getBlockDOMs, -1},+ {"/api/block/getBlockDOMsWithEmbed", `{"ids":[null]}`, getBlockDOMsWithEmbed, -1},+ {"/api/block/getBlockKramdown", `{"id":"20260101000000-abcdefg","mode":"invalid"}`, getBlockKramdown, -1},+ {"/api/block/getBlockKramdowns", `{"ids":[],"mode":"invalid"}`, getBlockKramdowns, -1},+ {"/api/notebook/setNotebookConf", `{"notebook":"invalid","conf":null}`, setNotebookConf, -1},+ {"/api/notebook/reorder", `{}`, reorderNotebooks, -1},+ {"/api/notebook/openNotebook", `{"notebook":"invalid"}`, openNotebook, -1},+ {"/api/notebook/getNotebookConf", `{"notebook":" 20260101000000-abcdefg "}`, getNotebookConf, -1},+ {"/api/notebook/enableEncryptedNotebooks", `{"password":" "}`, enableEncryptedNotebooks, -1},+ {"/api/notebook/createEncryptedNotebook", `{"name":"name","password":null}`, createEncryptedNotebook, -1},+ {"/api/notebook/unlockNotebook", `{"notebook":"invalid","password":"password"}`, unlockNotebook, -1},+ {"/api/notebook/unlockAndOpenNotebook", `{"notebook":"invalid","password":"password"}`, unlockAndOpenNotebook, -1},+ {"/api/notebook/lockNotebook", `{"notebook":"invalid"}`, lockNotebook, -1},+ {"/api/notebook/setNotebookCryptoAutoLock", `{"autoLockMinutes":"1"}`, setNotebookCryptoAutoLock, -1},+ {"/api/notebook/changeMasterPassword", `{"oldPassword":"old","newPassword":" "}`, changeMasterPassword, -1},{"/api/notebook/createNotebook", `{}`, createNotebook, -1},{"/api/notebook/setNotebookIcon", `{"notebook":"../escape","icon":""}`, setNotebookIcon, -1},{"/api/notebook/renameNotebook", `{"notebook":"invalid","name":"name"}`, renameNotebook, -1},diff --git a/kernel/api/contract_block_transaction.go b/kernel/api/contract_block_transaction.gonew file mode 100644index 0000000000..2d564f542a--- /dev/null+++ b/kernel/api/contract_block_transaction.go@@ -0,0 +1,132 @@+package api++import (+ "encoding/json"+ "fmt"++ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/model"+)++func blockOperationContract(operation *model.Operation) (*apicontract.BlockOperation, error) {+ if operation == nil {+ return nil, nil+ }+ if operation.Srcs != nil || len(operation.CellUpdates) > 0 {+ return nil, fmt.Errorf("unexpected attribute view payload in block operation [%s]", operation.Action)+ }+ ret := &apicontract.BlockOperation{+ Action: operation.Action,+ ID: operation.ID,+ RootID: operation.RootID,+ ParentID: operation.ParentID,+ PreviousID: operation.PreviousID,+ NextID: operation.NextID,+ BlockIDs: operation.BlockIDs,+ BlockID: operation.BlockID,+ DeckID: operation.DeckID,+ AvID: operation.AvID,+ SrcIDs: operation.SrcIDs,+ IsDetached: operation.IsDetached,+ Name: operation.Name,+ Typ: operation.Typ,+ Format: operation.Format,+ KeyID: operation.KeyID,+ RowID: operation.RowID,+ IsTwoWay: operation.IsTwoWay,+ BackRelationKeyID: operation.BackRelationKeyID,+ RemoveDest: operation.RemoveDest,+ Layout: string(operation.Layout),+ GroupID: operation.GroupID,+ TargetGroupID: operation.TargetGroupID,+ ViewID: operation.ViewID,+ ViewIDs: operation.ViewIDs,+ IgnoreDefaultFill: operation.IgnoreDefaultFill,+ }+ // 业务模型中的多态字段按块操作的有限载荷绑定,拒绝不属于该协议的类型。+ data, err := json.Marshal(operation.Data)+ if err != nil {+ return nil, err+ }+ if err = json.Unmarshal(data, &ret.Data); err != nil {+ return nil, err+ }+ data, err = json.Marshal(operation.RetData)+ if err != nil {+ return nil, err+ }+ if err = json.Unmarshal(data, &ret.RetData); err != nil {+ return nil, err+ }+ data, err = json.Marshal(operation.Context)+ if err != nil {+ return nil, err+ }+ var contextFields map[string]*string+ if err = json.Unmarshal(data, &contextFields); err != nil {+ return nil, err+ }+ if contextFields != nil {+ ret.Context = make(map[string]string, len(contextFields))+ for key, value := range contextFields {+ if value == nil {+ return nil, fmt.Errorf("block operation context [%s] must be text", key)+ }+ ret.Context[key] = *value+ }+ }+ return ret, nil+}++func blockOperationsContract(operations []*model.Operation) ([]*apicontract.BlockOperation, error) {+ if operations == nil {+ return nil, nil+ }+ ret := make([]*apicontract.BlockOperation, len(operations))+ for i, operation := range operations {+ converted, err := blockOperationContract(operation)+ if err != nil {+ return nil, err+ }+ ret[i] = converted+ }+ return ret, nil+}++func blockTransactionContract(transaction *model.Transaction) (*apicontract.BlockTransaction, error) {+ if transaction == nil {+ return nil, nil+ }+ do, err := blockOperationsContract(transaction.DoOperations)+ if err != nil {+ return nil, err+ }+ undo, err := blockOperationsContract(transaction.UndoOperations)+ if err != nil {+ return nil, err+ }+ return &apicontract.BlockTransaction{Timestamp: transaction.Timestamp, DoOperations: do, UndoOperations: undo, TemplateDocTreePlanID: transaction.TemplateDocTreePlanID}, nil+}++func blockTransactionResponse(transaction *model.Transaction) apicontract.Response[*apicontract.BlockTransaction] {+ converted, err := blockTransactionContract(transaction)+ if err != nil {+ return apicontract.Failure[*apicontract.BlockTransaction](-1, err.Error())+ }+ return apicontract.Success(converted)+}++func blockTransactionsResponse(transactions []*model.Transaction) apicontract.Response[[]*apicontract.BlockTransaction] {+ var ret []*apicontract.BlockTransaction+ if transactions != nil {+ ret = make([]*apicontract.BlockTransaction, len(transactions))+ }+ for i, transaction := range transactions {+ converted, err := blockTransactionContract(transaction)+ if err != nil {+ return apicontract.Failure[[]*apicontract.BlockTransaction](-1, err.Error())+ }+ ret[i] = converted+ }+ return apicontract.Success(ret)+}diff --git a/kernel/api/contract_block_transaction_test.go b/kernel/api/contract_block_transaction_test.gonew file mode 100644index 0000000000..072212c6ef--- /dev/null+++ b/kernel/api/contract_block_transaction_test.go@@ -0,0 +1,286 @@+package api++import (+ "context"+ "encoding/json"+ "net/http/httptest"+ "os"+ "os/exec"+ "path/filepath"+ "strings"+ "testing"+ "time"++ "github.com/88250/lute/ast"+ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/filesys"+ "github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/sql"+ "github.com/siyuan-note/siyuan/kernel/treenode"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestAPIContractBlockTransactionConversion(t *testing.T) {+ for _, transaction := range []*model.Transaction{nil, {}, {DoOperations: []*model.Operation{}, UndoOperations: []*model.Operation{}}, {Timestamp: 123, TemplateDocTreePlanID: "plan", DoOperations: []*model.Operation{nil, {Action: "insert", ID: "id", RootID: "root", ParentID: "parent", PreviousID: "previous", NextID: "next", Data: "<div>text</div>", RetData: []string{}, BlockIDs: []string{"child"}, Context: map[string]any{"ignoreProcess": "true"}}}, UndoOperations: []*model.Operation{{Action: "delete", ID: "id", RetData: "text", Context: map[string]any{}}, {Action: "foldHeading", RetData: []string{"child"}}}}} {+ before, err := json.Marshal(transaction)+ if err != nil {+ t.Fatal(err)+ }+ converted, err := blockTransactionContract(transaction)+ if err != nil {+ t.Fatal(err)+ }+ after, err := json.Marshal(converted)+ if err != nil || string(before) != string(after) {+ t.Fatalf("transaction JSON changed: %s != %s, %v", before, after, err)+ }+ recorder := httptest.NewRecorder()+ recorder.Header().Set("Content-Type", "application/json")+ body, err := json.Marshal(apicontract.Success(converted))+ if err != nil {+ t.Fatal(err)+ }+ recorder.Write(body)+ requireAPIContract(t, "POST", "/api/block/getHeadingDeleteTransaction", recorder)+ }+ for _, operation := range []*model.Operation{{Data: 42}, {RetData: map[string]any{"unexpected": true}}, {Srcs: []map[string]any{{"id": "id"}}}, {CellUpdates: []*model.AttrViewCellUpdate{{KeyID: "key"}}}, {Context: map[string]any{"unexpected": true}}} {+ if _, err := blockOperationContract(operation); err == nil {+ t.Fatalf("unexpected payload accepted: %+v", operation)+ }+ }+}++func TestAPIContractHeadingTransactions(t *testing.T) {+ if os.Getenv("SIYUAN_TEST_CONTRACT_HEADING") != "1" {+ ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)+ defer cancel()+ command := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestAPIContractHeadingTransactions$", "-test.v")+ command.Env = append(os.Environ(), "SIYUAN_TEST_CONTRACT_HEADING=1")+ if output, err := command.CombinedOutput(); err != nil {+ t.Fatalf("heading subprocess failed: %v\n%s", err, output)+ }+ return+ }+ root := t.TempDir()+ util.DataDir, util.TempDir, util.ConfDir = filepath.Join(root, "data"), root, root+ util.QueueDir = filepath.Join(root, "queue")+ util.HistoryDir = filepath.Join(root, "history")+ util.DBPath, util.HistoryDBPath, util.AssetContentDBPath, util.BlockTreeDBPath = filepath.Join(root, "siyuan.db"), filepath.Join(root, "history.db"), filepath.Join(root, "asset_content.db"), filepath.Join(root, "blocktree.db")+ model.Conf = model.NewAppConf()+ model.Conf.FileTree, model.Conf.Sync, model.Conf.NotebookCrypto = conf.NewFileTree(), conf.NewSync(), conf.NewNotebookCrypto()+ model.Conf.Search, model.Conf.Editor, model.Conf.Export = conf.NewSearch(), conf.NewEditor(), conf.NewExport()+ box := &model.Box{ID: ast.NewNodeID()}+ boxConf := conf.NewBoxConf()+ boxConf.Closed = false+ if err := box.SaveConf(boxConf); err != nil {+ t.Fatal(err)+ }+ sql.InitDatabase(true)+ sql.InitHistoryDatabase(true)+ sql.InitAssetContentDatabase(true)+ defer sql.CloseDatabase()+ docID := ast.NewNodeID()+ tree := treenode.NewTree(box.ID, "/"+docID+".sy", "/Contract", "Contract")+ paragraphID := tree.Root.FirstChild.ID+ heading := &ast.Node{Type: ast.NodeHeading, ID: ast.NewNodeID(), HeadingLevel: 1}+ heading.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte("Contract heading")})+ tree.Root.AppendChild(heading)+ child := &ast.Node{Type: ast.NodeHeading, ID: ast.NewNodeID(), HeadingLevel: 2}+ child.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte("Contract child")})+ tree.Root.AppendChild(child)+ if _, err := filesys.WriteTree(tree); err != nil {+ t.Fatal(err)+ }+ treenode.UpsertBlockTree(tree)+ engine := gin.New()+ engine.POST("/api/block/foldBlock", foldBlock)+ engine.POST("/api/block/unfoldBlock", unfoldBlock)+ engine.POST("/api/block/moveBlock", moveBlock)+ engine.POST("/api/block/getHeadingDeleteTransaction", getHeadingDeleteTransaction)+ engine.POST("/api/block/getHeadingInsertTransaction", getHeadingInsertTransaction)+ engine.POST("/api/block/getHeadingFoldTransaction", getHeadingFoldTransaction)+ for _, entry := range []struct {+ path, id, scope string+ code int+ empty bool+ }{+ {"getHeadingDeleteTransaction", heading.ID, "", 0, false},+ {"getHeadingInsertTransaction", heading.ID, "", 0, false},+ {"getHeadingFoldTransaction", heading.ID, "children", 0, false},+ {"getHeadingFoldTransaction", heading.ID, "invalid", -1, false},+ {"getHeadingDeleteTransaction", ast.NewNodeID(), "", -1, false},+ {"getHeadingInsertTransaction", ast.NewNodeID(), "", -1, false},+ {"getHeadingDeleteTransaction", paragraphID, "", 0, true},+ } {+ path := "/api/block/" + entry.path+ body, _ := json.Marshal(map[string]string{"id": entry.id, "scope": entry.scope})+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", path, strings.NewReader(string(body))))+ requireAPIContract(t, "POST", path, recorder)+ var response struct {+ Code int `json:"code"`+ Data json.RawMessage `json:"data"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != entry.code {+ t.Fatalf("heading response changed: %s, %v", recorder.Body.String(), err)+ }+ if entry.empty {+ if string(response.Data) != "null" {+ t.Fatalf("non-heading result must be null: %s", recorder.Body.String())+ }+ } else if entry.code == 0 {+ var transaction apicontract.BlockTransaction+ if err := json.Unmarshal(response.Data, &transaction); err != nil || len(transaction.DoOperations) == 0 || len(transaction.UndoOperations) == 0 {+ t.Fatalf("missing heading operations: %s, %v", recorder.Body.String(), err)+ }+ }+ }+ for _, entry := range []struct{ path, body, fold string }{+ {"foldBlock", `{"id":"` + heading.ID + `"}`, "1"},+ {"unfoldBlock", `{"id":"` + heading.ID + `"}`, ""},+ {"moveBlock", `{"id":"` + paragraphID + `","previousID":"` + child.ID + `"}`, ""},+ } {+ path := "/api/block/" + entry.path+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", path, strings.NewReader(entry.body)))+ requireAPIContract(t, "POST", path, recorder)+ var response struct {+ Code int `json:"code"`+ Data json.RawMessage `json:"data"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != 0 || string(response.Data) != "null" {+ t.Fatalf("block mutation response changed: %s, %v", recorder.Body.String(), err)+ }+ updated, err := model.LoadTreeByBlockID(heading.ID)+ if err != nil {+ t.Fatal(err)+ }+ if node := treenode.GetNodeInTree(updated, heading.ID); node == nil || node.IALAttr("fold") != entry.fold {+ t.Fatalf("heading fold state changed after %s", entry.path)+ }+ if entry.path == "moveBlock" {+ node := treenode.GetNodeInTree(updated, paragraphID)+ if node == nil || node.Previous == nil || node.Previous.ID != child.ID {+ t.Fatal("block was not moved after target")+ }+ }+ }+ testAPIContractBlockEdits(t, engine, box.ID, docID, heading.ID)+}++func testAPIContractBlockEdits(t *testing.T, engine *gin.Engine, boxID, docID, headingID string) {+ for _, route := range []struct {+ name string+ handler gin.HandlerFunc+ }{+ {"appendBlock", appendBlock}, {"prependBlock", prependBlock}, {"insertBlock", insertBlock},+ {"batchAppendBlock", batchAppendBlock}, {"batchPrependBlock", batchPrependBlock}, {"batchInsertBlock", batchInsertBlock},+ {"updateBlock", updateBlock}, {"batchUpdateBlock", batchUpdateBlock}, {"deleteBlock", deleteBlock},+ {"moveOutlineHeading", moveOutlineHeading}, {"updateTaskListItemMarker", updateTaskListItemMarker},+ {"batchUpdateTaskListItemMarker", batchUpdateTaskListItemMarker},+ {"appendDailyNoteBlock", appendDailyNoteBlock}, {"prependDailyNoteBlock", prependDailyNoteBlock},+ } {+ engine.POST("/api/block/"+route.name, route.handler)+ }+ post := func(name string, request any) []*apicontract.BlockTransaction {+ t.Helper()+ body, err := json.Marshal(request)+ if err != nil {+ t.Fatal(err)+ }+ path := "/api/block/" + name+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", path, strings.NewReader(string(body))))+ requireAPIContract(t, "POST", path, recorder)+ var result struct {+ Code int `json:"code"`+ Data []*apicontract.BlockTransaction `json:"data"`+ }+ if err = json.Unmarshal(recorder.Body.Bytes(), &result); err != nil || result.Code != 0 {+ t.Fatalf("%s failed: %s, %v", name, recorder.Body.String(), err)+ }+ return result.Data+ }+ parentInput := func(content string) map[string]any {+ return map[string]any{"parentID": docID, "data": content, "dataType": "markdown"}+ }+ for _, name := range []string{"batchAppendBlock", "batchPrependBlock", "batchInsertBlock"} {+ if result := post(name, map[string]any{"blocks": []any{}}); result != nil {+ t.Fatalf("%s empty input must return null", name)+ }+ }+ appendInput := parentInput("append text")+ appendInput["parentID"], appendInput["dataType"] = " "+docID+" ", " markdown "+ appended := post("appendBlock", appendInput)+ if len(appended) != 1 || len(appended[0].DoOperations) == 0 || appended[0].DoOperations[0].ID == "" {+ t.Fatal("append did not return inserted block ID")+ }+ appendID := appended[0].DoOperations[0].ID+ post("prependBlock", parentInput("prepend text"))+ post("insertBlock", map[string]any{"previousID": appendID, "data": "insert text", "dataType": "markdown", "parentID": nil})+ for _, name := range []string{"batchAppendBlock", "batchPrependBlock", "batchInsertBlock"} {+ post(name, map[string]any{"blocks": []any{parentInput(name + " first"), parentInput(name + " second")}})+ }+ post("updateBlock", map[string]any{"id": " " + appendID + " ", "data": "updated text", "dataType": " markdown ", "lockType": nil})+ post("batchUpdateBlock", map[string]any{"blocks": []any{map[string]any{"id": appendID, "data": "batch updated text", "dataType": "markdown", "lockType": true}}})+ post("moveOutlineHeading", map[string]any{"id": headingID, "previousID": appendID})+ post("appendBlock", parentInput("- [ ] task"))+ tree, err := model.LoadTreeByBlockID(docID)+ if err != nil {+ t.Fatal(err)+ }+ taskID := ""+ ast.Walk(tree.Root, func(node *ast.Node, entering bool) ast.WalkStatus {+ if entering && node.Type == ast.NodeListItem && node.ListData.Typ == 3 {+ taskID = node.ID+ }+ return ast.WalkContinue+ })+ if taskID == "" {+ t.Fatal("task fixture missing")+ }+ post("updateTaskListItemMarker", map[string]any{"id": " " + taskID + " ", "marker": "x"})+ post("batchUpdateTaskListItemMarker", map[string]any{"items": []any{map[string]string{"id": taskID, "marker": "x"}, map[string]string{"id": taskID, "marker": " "}}})+ tree, err = model.LoadTreeByBlockID(docID)+ if err != nil {+ t.Fatal(err)+ }+ marker := treenode.GetNodeInTree(tree, taskID).ChildByType(ast.NodeTaskListItemMarker)+ if marker == nil || marker.TaskListItemMarker != ' ' {+ t.Fatal("batch marker did not retain the last value")+ }+ post("deleteBlock", map[string]string{"id": " " + appendID + " "})+ tree, err = model.LoadTreeByBlockID(docID)+ if err != nil {+ t.Fatal(err)+ }+ if treenode.GetNodeInTree(tree, appendID) != nil {+ t.Fatal("block was not deleted")+ }+ box := &model.Box{ID: boxID}+ boxConf := box.GetConf()+ boxConf.DailyNoteSavePath = "/Contract"+ if err = box.SaveConf(boxConf); err != nil {+ t.Fatal(err)+ }+ post("appendDailyNoteBlock", map[string]string{"notebook": boxID, "data": "daily append", "dataType": "markdown"})+ post("prependDailyNoteBlock", map[string]string{"notebook": boxID, "data": "daily prepend", "dataType": "markdown"})+ updated := post("updateBlock", map[string]string{"id": docID, "data": "replacement document", "dataType": "markdown"})+ if len(updated) == 0 {+ t.Fatal("document update did not return operations")+ }+ data, err := json.Marshal(updated)+ if err != nil || !strings.Contains(string(data), `"createEmptyParagraph":false`) {+ t.Fatalf("document deletion options missing: %s, %v", data, err)+ }+ tree, err = model.LoadTreeByBlockID(docID)+ if err != nil {+ t.Fatal(err)+ }+ data, err = json.Marshal(tree.Root)+ if err != nil || !strings.Contains(string(data), "replacement document") || strings.Contains(string(data), "daily append") {+ t.Fatalf("document content was not replaced: %s, %v", data, err)+ }+}diff --git a/kernel/api/contract_notebook_test.go b/kernel/api/contract_notebook_test.gonew file mode 100644index 0000000000..eca4fc65ff--- /dev/null+++ b/kernel/api/contract_notebook_test.go@@ -0,0 +1,93 @@+package api++import (+ "bytes"+ "encoding/json"+ "mime/multipart"+ "net/http"+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/model"+)++func TestAPIContractNotebookConfConversion(t *testing.T) {+ for _, bytes := range [][]byte{nil, {}, {0, 1, 254, 255}} {+ value := conf.NewBoxConf()+ value.BoxCrypt = &conf.BoxEncryption{Spec: 2, WrappedDEK: bytes, WrapNonce: bytes, Metadata: bytes, CreatedAt: 1234567890}+ before, err := json.Marshal(value)+ if err != nil {+ t.Fatal(err)+ }+ after, err := json.Marshal(notebookConfContract(value))+ if err != nil || string(before) != string(after) {+ t.Fatalf("configuration serialization changed: %s != %s, %v", before, after, err)+ }+ }+ value := conf.NewBoxConf()+ before, _ := json.Marshal(value)+ after, err := json.Marshal(notebookConfContract(value))+ if err != nil || string(before) != string(after) {+ t.Fatalf("unencrypted configuration serialization changed: %v", err)+ }+}++func TestAPIContractNotebookBackupMissingFile(t *testing.T) {+ var body bytes.Buffer+ writer := multipart.NewWriter(&body)+ if err := writer.WriteField("password", " secret "); err != nil {+ t.Fatal(err)+ }+ if err := writer.Close(); err != nil {+ t.Fatal(err)+ }+ engine := gin.New()+ engine.POST("/api/notebook/importNotebookCryptoBackup", importNotebookCryptoBackup)+ request := httptest.NewRequest(http.MethodPost, "/api/notebook/importNotebookCryptoBackup", &body)+ request.Header.Set("Content-Type", writer.FormDataContentType())+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, request)+ requireAPIContract(t, http.MethodPost, request.URL.Path, recorder)+ var response struct {+ Code int `json:"code"`+ Msg string `json:"msg"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != -1 || response.Msg != "file not found" {+ t.Fatalf("missing backup error changed: %s, %v", recorder.Body.String(), err)+ }+}++func TestAPIContractNotebookInfoConversion(t *testing.T) {+ for _, info := range []*model.BoxInfo{nil, {}, {ID: "20260101000000-abcdefg", Name: "Notebook", DocCount: 12, Size: 123456789, HSize: "117.7 MB", Mtime: 1700000000, CTime: 1600000000, HMtime: "now", HCtime: "ago"}} {+ before, err := json.Marshal(info)+ if err != nil {+ t.Fatal(err)+ }+ after, err := json.Marshal(notebookInfoContract(info))+ if err != nil || string(before) != string(after) {+ t.Fatalf("notebook info serialization changed: %s != %s, %v", before, after, err)+ }+ }+}++func TestAPIContractNotebookCryptoAuthorization(t *testing.T) {+ gin.SetMode(gin.TestMode)+ for _, role := range []model.Role{model.RoleReader, model.RoleEditor} {+ engine := gin.New()+ engine.Use(func(c *gin.Context) {+ c.Set(model.RoleContextKey, role)+ c.Next()+ })+ ServeAPI(engine)+ for _, name := range []string{"enableEncryptedNotebooks", "disableEncryptedNotebooks", "createEncryptedNotebook", "unlockNotebook", "unlockAndOpenNotebook", "lockNotebook", "setNotebookCryptoAutoLock", "changeMasterPassword", "exportNotebookCryptoBackup", "importNotebookCryptoBackup"} {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, "/api/notebook/"+name, strings.NewReader(`{}`)))+ if recorder.Code != http.StatusForbidden {+ t.Fatalf("role %v reached %s: %d %s", role, name, recorder.Code, recorder.Body.String())+ }+ }+ }+}diff --git a/kernel/api/contract_word_count_test.go b/kernel/api/contract_word_count_test.gonew file mode 100644index 0000000000..c0cbda7561--- /dev/null+++ b/kernel/api/contract_word_count_test.go@@ -0,0 +1,130 @@+package api++import (+ "encoding/json"+ "net/http/httptest"+ "reflect"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestAPIContractChildBlockConversion(t *testing.T) {+ for _, blocks := range [][]*model.ChildBlock{nil, {}, {nil}, {{ID: "id", Type: "p"}}, {{ID: "id", Type: "l", SubType: "o", Content: "text", Markdown: "1. text"}}} {+ before, _ := json.Marshal(blocks)+ after, err := json.Marshal(childBlockContracts(blocks))+ if err != nil || string(before) != string(after) {+ t.Fatalf("child JSON changed: %s != %s, %v", before, after, err)+ }+ }+}++func TestAPIContractDocInfoConversion(t *testing.T) {+ for _, values := range [][]*model.BlockInfo{nil, {}, {nil}, {{ID: "id", RootID: "root", Name: "name", RefCount: 2, SubFileCount: 3, RefIDs: []string{"ref"}, IAL: map[string]string{"bookmark": "mark"}, Icon: "icon", AttrViews: []*model.AttrView{nil, {ID: "av", Name: "view"}}}}, {{RefIDs: []string{}, IAL: map[string]string{}, AttrViews: []*model.AttrView{}}}} {+ before, _ := json.Marshal(values)+ after, err := json.Marshal(docInfoContracts(values))+ if err != nil || string(before) != string(after) {+ t.Fatalf("document info JSON changed: %s != %s, %v", before, after, err)+ }+ }+}++func TestAPIContractTreeStatConversion(t *testing.T) {+ for _, stat := range []*model.DocumentStat{nil, {}, {Stat: &util.BlockStatResult{WordCount: 4}, ContainsEmbed: true, StatWithEmbed: &util.BlockStatResult{WordCount: 9}, EmbedStat: &model.EmbedStat{Complete: true, QueryEmbedCount: 1, JSEmbedCount: 2, ResultCount: 3, FailedQueryCount: 4, FailedResultCount: 5, TruncatedQueryCount: 6, CycleCount: 7, DepthLimitCount: 8}}} {+ for _, includeEmbed := range []bool{false, true} {+ expected := map[string]any{"reqId": nil, "stat": nil, "containsEmbed": false}+ if stat != nil {+ expected["stat"], expected["containsEmbed"] = stat.Stat, stat.ContainsEmbed+ if includeEmbed {+ expected["statWithEmbed"], expected["embedStat"] = stat.StatWithEmbed, stat.EmbedStat+ }+ }+ body, err := json.Marshal(apicontract.Success(treeStatContract(apicontract.JSONValue{}, stat, includeEmbed)))+ if err != nil {+ t.Fatal(err)+ }+ recorder := httptest.NewRecorder()+ recorder.Header().Set("Content-Type", "application/json; charset=utf-8")+ recorder.Write(body)+ requireAPIContract(t, "POST", "/api/block/getTreeStat", recorder)+ var actual struct {+ Data map[string]any `json:"data"`+ }+ if err = json.Unmarshal(body, &actual); err != nil {+ t.Fatal(err)+ }+ before, _ := json.Marshal(expected)+ var normalized map[string]any+ if err = json.Unmarshal(before, &normalized); err != nil {+ t.Fatal(err)+ }+ if !reflect.DeepEqual(normalized, actual.Data) {+ t.Fatalf("tree stat JSON changed: %s != %s", before, body)+ }+ }+ }+}++func TestAPIContractBlockTreeConversion(t *testing.T) {+ for _, values := range []map[string]*model.BlockTreeInfo{nil, {}, {"nil": nil}, {"id": {ID: "id", Type: "p", ParentID: "parent", ParentType: "d", PreviousID: "previous", PreviousType: "h", NextID: "next", NextType: "l"}}} {+ before, _ := json.Marshal(values)+ after, err := json.Marshal(blockTreeInfoContracts(values))+ if err != nil || string(before) != string(after) {+ t.Fatalf("tree info JSON changed: %s != %s, %v", before, after, err)+ }+ }+ for _, values := range [][]*model.BlockPath{nil, {}, {nil}, {{ID: "id", Name: "name", Type: "NodeList", SubType: "u", HasChildren: true, Children: []*model.BlockPath{{ID: "child", Children: []*model.BlockPath{}}}}}} {+ before, _ := json.Marshal(values)+ after, err := json.Marshal(blockPathContracts(values))+ if err != nil || string(before) != string(after) {+ t.Fatalf("breadcrumb JSON changed: %s != %s, %v", before, after, err)+ }+ }+}++func TestAPIContractRefDefsConversion(t *testing.T) {+ for _, values := range [][]*model.RefDefs{nil, {}, {nil}, {{RefID: "ref", DefIDs: nil}}, {{RefID: "ref", DefIDs: []string{}}}, {{RefID: "ref", DefIDs: []string{"def"}}}} {+ before, _ := json.Marshal(values)+ after, err := json.Marshal(refDefContracts(values))+ if err != nil || string(before) != string(after) {+ t.Fatalf("reference JSON changed: %s != %s, %v", before, after, err)+ }+ }+}++func TestAPIContractWordCountCorrelation(t *testing.T) {+ engine := gin.New()+ engine.POST("/api/block/getContentWordCount", getContentWordCount)+ for _, value := range []string{`null`, `1.0`, `"request"`, `true`, `[1,null,"x"]`, `{"nested":{"values":[false,2]}}`} {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/block/getContentWordCount", strings.NewReader(`{"content":"","reqId":`+value+`}`)))+ requireAPIContract(t, "POST", "/api/block/getContentWordCount", recorder)+ var result struct {+ Code int `json:"code"`+ Data struct {+ ReqID any `json:"reqId"`+ } `json:"data"`+ }+ var expected any+ if err := json.Unmarshal([]byte(value), &expected); err != nil {+ t.Fatal(err)+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &result); err != nil || result.Code != 0 || !reflect.DeepEqual(result.Data.ReqID, expected) {+ t.Fatalf("correlation value changed: %s, %v", recorder.Body.String(), err)+ }+ }+}++func TestAPIContractBlockStatConversion(t *testing.T) {+ for _, stat := range []*util.BlockStatResult{nil, {}, {RuneCount: 12, WordCount: 3, LinkCount: 2, ImageCount: 4, RefCount: 5, BlockCount: 6}} {+ before, _ := json.Marshal(stat)+ after, err := json.Marshal(blockStatContract(stat))+ if err != nil || string(before) != string(after) {+ t.Fatalf("stat JSON changed: %s != %s, %v", before, after, err)+ }+ }+}diff --git a/kernel/api/notebook.go b/kernel/api/notebook.goindex f8ca3fd113..ff77625a7b 100644--- a/kernel/api/notebook.go+++ b/kernel/api/notebook.go@@ -17,9 +17,7 @@package apiimport (- "fmt""io"- "net/http""sort""strings""time"@@ -32,45 +30,33 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-func getNotebookInfo(c *gin.Context) {+var getNotebookInfo = contractHandler(apicontract.GetNotebookInfo, func(c *gin.Context, request apicontract.NotebookIDRequest) apicontract.Response[apicontract.NotebookInfoData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var boxID string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("notebook", &boxID, true, true)) {- return- }+ boxID := request.Notebookif util.InvalidIDPattern(boxID, ret) {- return+ return contractFailure[apicontract.NotebookInfoData](ret)}box := model.Conf.Box(boxID)if nil == box {ret.Code = -1ret.Msg = "notebook [" + boxID + "] not found"- return+ return contractFailure[apicontract.NotebookInfoData](ret)}if model.IsReadOnlyRoleContext(c) && !isNotebookVisibleByPublishAccess(box, model.GetPublishAccess()) {ret.Code = -1ret.Msg = "notebook [" + boxID + "] not found"- return+ return contractFailure[apicontract.NotebookInfoData](ret)}if err := holdEncryptedBoxRequest(c, boxID); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[apicontract.NotebookInfoData](ret)}boxInfo := box.GetInfo()- ret.Data = map[string]any{- "boxInfo": boxInfo,- }-}+ return apicontract.Success(apicontract.NotebookInfoData{BoxInfo: notebookInfoContract(boxInfo)})+})var setNotebookIcon = contractHandler(apicontract.SetNotebookIcon, func(c *gin.Context, request apicontract.SetNotebookIconRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()@@ -103,31 +89,22 @@ var changeSortNotebook = contractHandler(apicontract.ChangeSortNotebook, func(creturn apicontract.Success(apicontract.Null{})})-func reorderNotebooks(c *gin.Context) {+var reorderNotebooks = contractHandler(apicontract.ReorderNotebooks, func(c *gin.Context, request apicontract.ReorderNotebooksRequest) apicontract.Response[*apicontract.ReorderData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- request := &struct {- SourceIDs []string `json:"sourceIDs"`- TargetID string `json:"targetID"`- Position string `json:"position"`- }{}- if err := c.ShouldBindJSON(request); nil != err {- ret.Code = -1- ret.Msg = fmt.Sprintf("Parses request [%s] failed: %s", c.Request.URL.Path, err)- return- }if !validateReorderRequest(request.SourceIDs, request.TargetID, request.Position, ret) {- return+ return contractFailure[*apicontract.ReorderData](ret)}result, err := model.ReorderNotebooks(request.SourceIDs, request.TargetID, request.Position)- ret.Data = result+ var data *apicontract.ReorderData+ if result != nil {+ data = &apicontract.ReorderData{Changed: result.Changed, Notebook: result.Notebook, ParentPath: result.ParentPath}+ }if nil != err {- ret.Code = -1- ret.Msg = err.Error()+ return apicontract.ReorderNotebooks.FailureWithData(-1, err.Error(), data)}-}+ return apicontract.Success(data)+})var renameNotebook = contractHandler(apicontract.RenameNotebook, func(c *gin.Context, request apicontract.RenameNotebookRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()@@ -221,34 +198,24 @@ var createNotebook = contractHandler(apicontract.CreateNotebook, func(c *gin.Conreturn apicontract.Success(apicontract.CreateNotebookData{Notebook: notebookContract(box)})})-func openNotebook(c *gin.Context) {+var openNotebook = contractHandler(apicontract.OpenNotebook, func(c *gin.Context, request apicontract.OpenNotebookRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ notebook := request.Notebook- var notebook string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("notebook", ¬ebook, true, true)) {- return- }if util.InvalidIDPattern(notebook, ret) {- return+ return contractFailure[apicontract.Null](ret)}isUserGuide := model.IsUserGuide(notebook)if util.ReadOnly && !isUserGuide {ret.Code = -1ret.Msg = model.Conf.Language(34)- ret.Data = map[string]any{"closeTimeout": 5000}- return+ return apicontract.FailureWithTimeout[apicontract.Null](ret.Code, ret.Msg, 5000)}if err := holdEncryptedBoxRequest(c, notebook); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[apicontract.Null](ret)}msgId := util.PushMsg(model.Conf.Language(45), 1000*60*15)@@ -257,14 +224,14 @@ func openNotebook(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}box := model.Conf.Box(notebook)if nil == box {ret.Code = -1ret.Msg = "opened notebook [" + notebook + "] not found"- return+ return contractFailure[apicontract.Null](ret)}evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast)@@ -275,11 +242,7 @@ func openNotebook(c *gin.Context) {util.PushEvent(evt)if isUserGuide {- appArg := arg["app"]- app := ""- if nil != appArg {- app = appArg.(string)- }+ app := request.Appgo func() {var startID string@@ -302,7 +265,8 @@ func openNotebook(c *gin.Context) {}}()}-}+ return apicontract.Success(apicontract.Null{})+})var closeNotebook = contractHandler(apicontract.CloseNotebook, func(c *gin.Context, request apicontract.CloseNotebookRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()@@ -315,36 +279,30 @@ var closeNotebook = contractHandler(apicontract.CloseNotebook, func(c *gin.Contereturn apicontract.Success(apicontract.Null{})})-func getNotebookConf(c *gin.Context) {+var getNotebookConf = contractHandler(apicontract.GetNotebookConf, func(c *gin.Context, request apicontract.CloseNotebookRequest) apicontract.Response[apicontract.NotebookConfData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+ notebook := request.Notebook- notebook := arg["notebook"].(string)if util.InvalidIDPattern(notebook, ret) {- return+ return contractFailure[apicontract.NotebookConfData](ret)}box := model.Conf.GetBox(notebook)if nil == box {ret.Code = -1ret.Msg = "notebook [" + notebook + "] not found"- return+ return contractFailure[apicontract.NotebookConfData](ret)}if model.IsReadOnlyRoleContext(c) && !isNotebookVisibleByPublishAccess(box, model.GetPublishAccess()) {ret.Code = -1ret.Msg = "notebook [" + notebook + "] not found"- return+ return contractFailure[apicontract.NotebookConfData](ret)}if model.IsBoxUnlocked(notebook) {if err := holdEncryptedBoxRequest(c, notebook); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[apicontract.NotebookConfData](ret)}}@@ -352,61 +310,35 @@ func getNotebookConf(c *gin.Context) {if !model.IsAdminRoleContext(c) {model.HideBoxConfSecret(boxConf)}- ret.Data = map[string]any{- "box": box.ID,- "name": box.Name,- "conf": boxConf,- }-}-func setNotebookConf(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)+ return apicontract.Success(apicontract.NotebookConfData{Box: box.ID, Name: box.Name, Conf: notebookConfContract(boxConf)})+})- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }+var setNotebookConf = contractHandler(apicontract.SetNotebookConf, func(c *gin.Context, request apicontract.SetNotebookConfRequest) apicontract.Response[*apicontract.NotebookConf] {+ ret := gulu.Ret.NewResult()+ notebook := request.Notebook- notebook := arg["notebook"].(string)if util.InvalidIDPattern(notebook, ret) {- return+ return contractFailure[*apicontract.NotebookConf](ret)}box := model.Conf.GetBox(notebook)if nil == box {ret.Code = -1ret.Msg = "notebook [" + notebook + "] not found"- return+ return contractFailure[*apicontract.NotebookConf](ret)}if model.IsBoxUnlocked(notebook) {if err := holdEncryptedBoxRequest(c, notebook); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[*apicontract.NotebookConf](ret)}}- param, err := gulu.JSON.MarshalJSON(arg["conf"])- if err != nil {- ret.Code = -1- ret.Msg = err.Error()- return- }-boxConf := box.GetConf()oldSortMode := boxConf.SortMode- // 深拷贝加密相关字段,防止反序列化请求体时被覆盖- // BoxCrypt 是指针,UnmarshalJSON 会修改同一指针对象,必须用 model 层辅助函数深拷贝- savedBoxCrypt := model.DeepCopyBoxEncryption(boxConf.BoxCrypt)- savedEncrypted := boxConf.Encrypted- if err = gulu.JSON.UnmarshalJSON(param, boxConf); err != nil {- ret.Code = -1- ret.Msg = err.Error()- return- }- boxConf.Encrypted = savedEncrypted- boxConf.BoxCrypt = savedBoxCrypt+ applyNotebookConfPatch(boxConf, request.Conf)boxConf.DocCreateSavePath = util.TrimSpaceInPath(boxConf.DocCreateSavePath)boxConf.DocCreateTemplatePath = util.NormalizeTemplatePath(boxConf.DocCreateTemplatePath)@@ -422,7 +354,7 @@ func setNotebookConf(c *gin.Context) {if "/" == boxConf.DailyNoteSavePath {ret.Code = -1ret.Msg = model.Conf.Language(49)- return+ return contractFailure[*apicontract.NotebookConf](ret)}boxConf.DailyNoteTemplatePath = util.NormalizeTemplatePath(boxConf.DailyNoteTemplatePath)@@ -430,13 +362,13 @@ func setNotebookConf(c *gin.Context) {if err := box.SaveConf(boxConf); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[*apicontract.NotebookConf](ret)}if oldSortMode != boxConf.SortMode {model.PushDocSortModeChanged("notebook", notebook, "", "/", &boxConf.SortMode)}- ret.Data = boxConf-}+ return apicontract.Success(notebookConfContract(boxConf))+})var lsNotebooks = contractHandler(apicontract.ListNotebooks, func(c *gin.Context, request apicontract.ListNotebooksRequest) apicontract.Response[*apicontract.ListNotebooksData] {ret := gulu.Ret.NewResult()@@ -528,68 +460,45 @@ func isNotebookVisibleByPublishAccess(notebook *model.Box, publishAccess model.P}// enableEncryptedNotebooks 先同步数据,再恢复既有配置或启用加密笔记本并设置主密码。-func enableEncryptedNotebooks(c *gin.Context) {+var enableEncryptedNotebooks = contractHandler(apicontract.EnableEncryptedNotebooks, func(c *gin.Context, request apicontract.NotebookPasswordRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var password string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("password", &password, true, true)) {- return- }+ password := request.Passwordif err := model.EnableEncryptedNotebookWithSync(password); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}-}+ return apicontract.Success(apicontract.Null{})+})// disableEncryptedNotebooks 关闭加密笔记本功能。前置:没有加密笔记本存在。-func disableEncryptedNotebooks(c *gin.Context) {+var disableEncryptedNotebooks = contractHandler(apicontract.DisableEncryptedNotebooks, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-if err := model.DisableEncryptedNotebook(); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}-}+ return apicontract.Success(apicontract.Null{})+})// createEncryptedNotebook 创建一个新的加密笔记本。前置:加密功能已启用。// 创建时需提供主密码(用于派生 KEK 包络 DEK)。创建成功后内核已原子完成挂载。-func createEncryptedNotebook(c *gin.Context) {+var createEncryptedNotebook = contractHandler(apicontract.CreateEncryptedNotebook, func(c *gin.Context, request apicontract.CreateEncryptedNotebookRequest) apicontract.Response[apicontract.CreateNotebookData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var name, password string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("name", &name, true, false),- util.BindJsonArg("password", &password, true, true),- ) {- return- }+ name, password := request.Name, request.Passwordid, err := model.CreateEncryptedBox(name, password)if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.CreateNotebookData](ret)}if err = holdEncryptedBoxRequest(c, id); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[apicontract.CreateNotebookData](ret)}// 创建时 DEK 已缓存 + 加密 db 已打开,此处直接挂载;失败则锁定回滚,避免 DEK 残留@@ -599,7 +508,7 @@ func createEncryptedNotebook(c *gin.Context) {model.LockBox(id)ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.CreateNotebookData](ret)}box := model.Conf.Box(id)@@ -610,90 +519,63 @@ func createEncryptedNotebook(c *gin.Context) {}util.PushEvent(evt)- ret.Data = map[string]any{- "notebook": box,- }-}+ return apicontract.Success(apicontract.CreateNotebookData{Notebook: notebookContract(box)})+})// unlockNotebook 用主密码派生 KEK 并解出指定加密笔记本的 DEK,缓存到内存。// 解锁后该笔记本即可被 Mount。每次调用跑一次 Argon2id(约 1 秒)。-func unlockNotebook(c *gin.Context) {+var unlockNotebook = contractHandler(apicontract.UnlockNotebook, func(c *gin.Context, request apicontract.UnlockNotebookRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var notebook, password string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("notebook", ¬ebook, true, true),- util.BindJsonArg("password", &password, true, true),- ) {- return- }+ notebook, password := request.Notebook, request.Passwordif util.InvalidIDPattern(notebook, ret) {- return+ return contractFailure[apicontract.Null](ret)}boxCrypt, err := model.GetBoxEncryption(notebook)if err != nil {ret.Code = -1ret.Msg = model.Conf.Language(318)- return+ return contractFailure[apicontract.Null](ret)}if boxCrypt == nil || len(boxCrypt.WrappedDEK) == 0 {ret.Code = -1ret.Msg = model.Conf.Language(319)- return+ return contractFailure[apicontract.Null](ret)}if err := model.UnlockBox(notebook, password, boxCrypt); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}if err = holdEncryptedBoxRequest(c, notebook); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[apicontract.Null](ret)}-}+ return apicontract.Success(apicontract.Null{})+})// unlockAndOpenNotebook 原子化解锁并挂载加密笔记本,挂载失败时由模型层在同一转换锁内回滚本次解锁。-func unlockAndOpenNotebook(c *gin.Context) {+var unlockAndOpenNotebook = contractHandler(apicontract.UnlockAndOpenNotebook, func(c *gin.Context, request apicontract.UnlockNotebookRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var notebook, password string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("notebook", ¬ebook, true, true),- util.BindJsonArg("password", &password, true, true),- ) {- return- }+ notebook, password := request.Notebook, request.Passwordif util.InvalidIDPattern(notebook, ret) {- return+ return contractFailure[apicontract.Null](ret)}boxCrypt, err := model.GetBoxEncryption(notebook)if err != nil {ret.Code = -1ret.Msg = model.Conf.Language(318)- return+ return contractFailure[apicontract.Null](ret)}if boxCrypt == nil || len(boxCrypt.WrappedDEK) == 0 {ret.Code = -1ret.Msg = model.Conf.Language(319)- return+ return contractFailure[apicontract.Null](ret)}msgId := util.PushMsg(model.Conf.Language(45), 1000*60*15)@@ -702,12 +584,12 @@ func unlockAndOpenNotebook(c *gin.Context) {if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}if err = holdEncryptedBoxRequest(c, notebook); err != nil {ret.Code = -1ret.Msg = model.Conf.Language(314)- return+ return contractFailure[apicontract.Null](ret)}box := model.Conf.Box(notebook)@@ -716,7 +598,7 @@ func unlockAndOpenNotebook(c *gin.Context) {model.LockBox(notebook)ret.Code = -1ret.Msg = "opened notebook [" + notebook + "] not found"- return+ return contractFailure[apicontract.Null](ret)}evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast)@@ -725,97 +607,64 @@ func unlockAndOpenNotebook(c *gin.Context) {"existed": existed,}util.PushEvent(evt)-}+ return apicontract.Success(apicontract.Null{})+})// lockNotebook 锁定指定加密笔记本:清除其 DEK 缓存并 Unmount。-func lockNotebook(c *gin.Context) {+var lockNotebook = contractHandler(apicontract.LockNotebook, func(c *gin.Context, request apicontract.NotebookIDRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var notebook string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("notebook", ¬ebook, true, true)) {- return- }+ notebook := request.Notebookif util.InvalidIDPattern(notebook, ret) {- return+ return contractFailure[apicontract.Null](ret)}if !model.IsEncryptedBox(notebook) {ret.Code = -1ret.Msg = model.Conf.Language(319)- return+ return contractFailure[apicontract.Null](ret)}// Unmount 内部的 unmount0 会清 DEK + 关闭加密 db,无需单独 LockBox。// 反过来若先 LockBox 会关闭 db,导致 Unmount 的 Unindex 操作无 db 可用。model.Unmount(notebook)-}+ return apicontract.Success(apicontract.Null{})+})// setNotebookCryptoAutoLock 设置加密笔记本自动锁定闲置分钟数。-func setNotebookCryptoAutoLock(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var autoLockMinutes float64- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("autoLockMinutes", &autoLockMinutes, true, false)) {- return- }+var setNotebookCryptoAutoLock = contractHandler(apicontract.SetNotebookCryptoAutoLock, func(c *gin.Context, request apicontract.NotebookCryptoAutoLockRequest) apicontract.Response[apicontract.Null] {+ autoLockMinutes := request.AutoLockMinutesminutes := max(int(autoLockMinutes), 0)model.SetAutoLockMinutes(minutes)model.Conf.Save()-}+ return apicontract.Success(apicontract.Null{})+})// touchEncryptedNotebooks 由前端真实用户交互或 headless 客户端显式保活调用,刷新已解锁加密笔记本的闲置计时。-func touchEncryptedNotebooks(c *gin.Context) {+var touchEncryptedNotebooks = contractHandler(apicontract.TouchEncryptedNotebooks, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {model.TouchUnlockedEncryptedBoxes()- c.JSON(http.StatusOK, gulu.Ret.NewResult())-}+ return apicontract.Success(apicontract.Null{})+})// changeMasterPassword 修改加密笔记本的主密码。// 用旧密码校验后,用新密码派生新 KEK,重新加密 verifier 和所有加密笔记本的 WrappedDEK。// 必须在所有加密笔记本都已锁定(DEK 不在内存)的状态下调用。-func changeMasterPassword(c *gin.Context) {+var changeMasterPassword = contractHandler(apicontract.ChangeMasterPassword, func(c *gin.Context, request apicontract.ChangeMasterPasswordRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var oldPassword, newPassword string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("oldPassword", &oldPassword, true, true),- util.BindJsonArg("newPassword", &newPassword, true, true),- ) {- return- }+ oldPassword, newPassword := request.OldPassword, request.NewPasswordif err := model.ChangeMasterPassword(oldPassword, newPassword); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}-}+ return apicontract.Success(apicontract.Null{})+})// getEncryptedNotebookStatus 返回加密笔记本功能的启用状态和各笔记本解锁信息。-func getEncryptedNotebookStatus(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-+var getEncryptedNotebookStatus = contractHandler(apicontract.GetEncryptedNotebookStatus, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.EncryptedNotebookStatusData] {model.NotebookCryptoMuLock()boxIDs := model.ListAllEncryptedBoxIDs()model.NotebookCryptoMuUnlock()@@ -825,87 +674,58 @@ func getEncryptedNotebookStatus(c *gin.Context) {hasHistoryDependency := model.HasEncryptedNotebookHistory()state := model.NotebookCryptoLifecycleState(len(boxIDs) > 0 || hasHistoryDependency)- boxes := make([]map[string]any, 0, len(boxIDs))+ boxes := make([]apicontract.EncryptedNotebookStatus, 0, len(boxIDs))for _, id := range boxIDs {box := model.Conf.Box(id)name := ""if box != nil {name = box.Name}- boxes = append(boxes, map[string]any{- "id": id,- "name": name,- "unlocked": model.IsBoxUnlocked(id),- "state": model.GetEncryptedBoxState(id),- })+ boxes = append(boxes, apicontract.EncryptedNotebookStatus{ID: id, Name: name, Unlocked: model.IsBoxUnlocked(id), State: string(model.GetEncryptedBoxState(id))})}- ret.Data = map[string]any{- "enabled": state == model.NotebookCryptoStateEnabled,- "state": state,- "count": len(boxIDs),- "boxes": boxes,- "migrationPending": pendingMigration,- "migrationBoxes": migrationBoxes,- "hasHistoryDependency": hasHistoryDependency,- }-}+ return apicontract.Success(apicontract.EncryptedNotebookStatusData{+ Enabled: state == model.NotebookCryptoStateEnabled, State: string(state), Count: len(boxIDs), Boxes: boxes,+ MigrationPending: pendingMigration, MigrationBoxes: migrationBoxes, HasHistoryDependency: hasHistoryDependency,+ })+})// exportNotebookCryptoBackup 导出密钥备份文件到 export 目录供下载。// 备份文件不含主密码(salt 不保密、verifier 是密文),用户主动保存作为同步之外的独立恢复途径。-func exportNotebookCryptoBackup(c *gin.Context) {+var exportNotebookCryptoBackup = contractHandler(apicontract.ExportNotebookCryptoBackup, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.NotebookCryptoBackupData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-downloadPath, err := model.ExportNotebookCryptoBackup()if err != nil {ret.Code = -1ret.Msg = err.Error()- return- }- ret.Data = map[string]any{- "file": downloadPath,+ return contractFailure[apicontract.NotebookCryptoBackupData](ret)}-}+ return apicontract.Success(apicontract.NotebookCryptoBackupData{File: downloadPath})+})// importNotebookCryptoBackup 导入密钥备份文件,恢复加密配置。// 用于新设备、重装或 RecoveryRequired 状态下手动恢复;完整且已启用的配置拒绝覆盖。-func importNotebookCryptoBackup(c *gin.Context) {+var importNotebookCryptoBackup = contractHandler(apicontract.ImportNotebookCryptoBackup, func(c *gin.Context, request apicontract.ImportNotebookCryptoBackupRequest) apicontract.Response[apicontract.Null] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- form, err := c.MultipartForm()- if err != nil {- ret.Code = -1- ret.Msg = err.Error()- return- }- if 1 > len(form.File["file"]) {- ret.Code = -1- ret.Msg = "file not found"- return- }- fh := form.File["file"][0]+ fh := request.Filef, err := fh.Open()if err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}defer f.Close()data, err := io.ReadAll(f)if err != nil {ret.Code = -1ret.Msg = err.Error()- return- }- password := ""- if vals := form.Value["password"]; len(vals) > 0 {- password = vals[0]+ return contractFailure[apicontract.Null](ret)}+ password := request.Passwordif err := model.ImportNotebookCryptoBackup(data, password); err != nil {ret.Code = -1ret.Msg = err.Error()- return+ return contractFailure[apicontract.Null](ret)}-}+ return apicontract.Success(apicontract.Null{})+})diff --git a/kernel/api/notebook_patch.go b/kernel/api/notebook_patch.gonew file mode 100644index 0000000000..ab3d2043ff--- /dev/null+++ b/kernel/api/notebook_patch.go@@ -0,0 +1,49 @@+package api++import (+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/conf"+)++// applyNotebookConfPatch 仅更新提供的普通配置字段,加密参数由密钥生命周期接口管理。+func applyNotebookConfPatch(value *conf.BoxConf, patch *apicontract.NotebookConfPatch) {+ if patch == nil {+ return+ }+ if patch.Name != nil {+ value.Name = *patch.Name+ }+ if patch.Sort != nil {+ value.Sort = *patch.Sort+ }+ if patch.Icon != nil {+ value.Icon = *patch.Icon+ }+ if patch.Closed != nil {+ value.Closed = *patch.Closed+ }+ if patch.RefCreateSaveBox != nil {+ value.RefCreateSaveBox = *patch.RefCreateSaveBox+ }+ if patch.RefCreateSavePath != nil {+ value.RefCreateSavePath = *patch.RefCreateSavePath+ }+ if patch.DocCreateSaveBox != nil {+ value.DocCreateSaveBox = *patch.DocCreateSaveBox+ }+ if patch.DocCreateSavePath != nil {+ value.DocCreateSavePath = *patch.DocCreateSavePath+ }+ if patch.DocCreateTemplatePath != nil {+ value.DocCreateTemplatePath = *patch.DocCreateTemplatePath+ }+ if patch.DailyNoteSavePath != nil {+ value.DailyNoteSavePath = *patch.DailyNoteSavePath+ }+ if patch.DailyNoteTemplatePath != nil {+ value.DailyNoteTemplatePath = *patch.DailyNoteTemplatePath+ }+ if patch.SortMode != nil {+ value.SortMode = *patch.SortMode+ }+}diff --git a/kernel/api/notebook_patch_test.go b/kernel/api/notebook_patch_test.gonew file mode 100644index 0000000000..7eaa2da836--- /dev/null+++ b/kernel/api/notebook_patch_test.go@@ -0,0 +1,108 @@+package api++import (+ "encoding/json"+ "net/http/httptest"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/88250/gulu"+ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract"+ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/model"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestAPIContractNotebookConfPatchPersistence(t *testing.T) {+ oldConf, oldDataDir := model.Conf, util.DataDir+ util.DataDir = t.TempDir()+ model.Conf = model.NewAppConf()+ model.Conf.FileTree = conf.NewFileTree()+ t.Cleanup(func() { model.Conf, util.DataDir = oldConf, oldDataDir })+ const id = "20260101000000-abcdefg"+ path := filepath.Join(util.DataDir, id, ".siyuan", "conf.json")+ initial := conf.NewBoxConf()+ initial.Name = "original"+ data, _ := json.Marshal(initial)+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(path, data, 0644); err != nil {+ t.Fatal(err)+ }+ engine := gin.New()+ engine.POST("/api/notebook/setNotebookConf", setNotebookConf)+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/notebook/setNotebookConf", strings.NewReader(`{"notebook":"`+id+`","conf":{"dailyNoteSavePath":"daily","name":null,"encrypted":true,"boxCrypt":{"spec":1,"wrappedDEK":"AQID"}}}`)))+ requireAPIContract(t, "POST", "/api/notebook/setNotebookConf", recorder)+ var response struct {+ Code int `json:"code"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != 0 {+ t.Fatalf("patch failed: %s, %v", recorder.Body.String(), err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ var stored conf.BoxConf+ if err := json.Unmarshal(data, &stored); err != nil {+ t.Fatal(err)+ }+ if stored.Name != "original" || stored.DailyNoteSavePath != "/daily" || stored.Encrypted || stored.BoxCrypt != nil {+ t.Fatal("patch did not preserve ordinary and encryption configuration")+ }+}++func TestAPIContractNotebookConfPatchCompatibility(t *testing.T) {+ for _, payload := range []string{+ `null`, `{}`, `{"name":null,"sortMode":null,"closed":null}`, `{"name":"","closed":false,"sortMode":0}`,+ `{"Name":"upper","sort":1.0,"sortMode":2e0}`, `{"name":"lower","Name":"upper","unknown":true}`,+ `{"encrypted":false,"boxCrypt":null}`, `{"boxCrypt":{"spec":1,"wrappedDEK":"AQID","metadata":[1,2,3]}}`,+ `{"docCreateSaveBox":"box","docCreateSavePath":"/path","docCreateTemplatePath":"template","refCreateSaveBox":"ref","refCreateSavePath":"/ref","dailyNoteSavePath":"/daily","dailyNoteTemplatePath":"daily","icon":"icon"}`,+ `{"sort":1.5}`, `{"closed":1}`, `{"boxCrypt":{"wrappedDEK":"invalid"}}`, `{"boxCrypt":{"metadata":[256]}}`,+ } {+ t.Run(payload, func(t *testing.T) {+ initial := conf.NewBoxConf()+ initial.Encrypted = true+ initial.BoxCrypt = &conf.BoxEncryption{Spec: 1, WrappedDEK: []byte{9, 8, 7}, WrapNonce: []byte{6, 5, 4}, CreatedAt: 123}+ initialJSON, _ := json.Marshal(initial)+ var legacy conf.BoxConf+ if err := json.Unmarshal(initialJSON, &legacy); err != nil {+ t.Fatal(err)+ }+ var normalized any+ if err := gulu.JSON.UnmarshalJSON([]byte(payload), &normalized); err != nil {+ t.Fatal(err)+ }+ data, err := gulu.JSON.MarshalJSON(normalized)+ if err != nil {+ t.Fatal(err)+ }+ savedCrypt := model.DeepCopyBoxEncryption(legacy.BoxCrypt)+ legacyErr := gulu.JSON.UnmarshalJSON(data, &legacy)+ legacy.Encrypted = true+ legacy.BoxCrypt = savedCrypt+ request, decodeErr := apicontract.SetNotebookConf.Decode(strings.NewReader(`{"notebook":"20260101000000-abcdefg","conf":` + payload + `}`))+ if (legacyErr != nil) != (decodeErr != nil) {+ t.Fatalf("input acceptance changed: old %v, contract %v", legacyErr, decodeErr)+ }+ if decodeErr != nil {+ return+ }+ crypt := initial.BoxCrypt+ applyNotebookConfPatch(initial, request.Conf)+ if initial.BoxCrypt != crypt || !initial.Encrypted {+ t.Fatal("configuration patch modified encryption state")+ }+ before, _ := json.Marshal(&legacy)+ after, _ := json.Marshal(initial)+ if string(before) != string(after) {+ t.Fatalf("patch semantics changed: %s != %s", before, after)+ }+ })+ }+}diff --git a/kernel/api/notebook_security_test.go b/kernel/api/notebook_security_test.goindex bdc3adbc5d..80ba63b433 100644--- a/kernel/api/notebook_security_test.go+++ b/kernel/api/notebook_security_test.go@@ -160,6 +160,7 @@ func TestGetNotebookInfoHidesInvisibleNotebookFromReader(t *testing.T) {)request.Header.Set("Content-Type", "application/json")engine.ServeHTTP(recorder, request)+ requireAPIContract(t, http.MethodPost, "/api/notebook/getNotebookInfo", recorder)response := &struct {Code int `json:"code"`@@ -296,6 +297,7 @@ func TestGetNotebookConfHidesEncryptedNotebookFromReader(t *testing.T) {Conf *conf.BoxConf `json:"conf"`} `json:"data"`}{}+ requireAPIContract(t, http.MethodPost, "/api/notebook/getNotebookConf", recorder)if err := json.Unmarshal(recorder.Body.Bytes(), response); err != nil {t.Fatalf("unmarshal response failed: %v", err)}@@ -370,6 +372,7 @@ func TestGetEncryptedNotebookStatusAuthorization(t *testing.T) {t.Fatalf("%s request returned status %d: %s", test.name, recorder.Code, recorder.Body.String())}if test.role == model.RoleAdministrator {+ requireAPIContract(t, http.MethodPost, "/api/notebook/getEncryptedNotebookStatus", recorder)response := &struct {Code int `json:"code"`}{}diff --git a/kernel/apicontract/block.go b/kernel/apicontract/block.goindex 0c0600ff9c..3d16b97514 100644--- a/kernel/apicontract/block.go+++ b/kernel/apicontract/block.go@@ -1,5 +1,73 @@package apicontract+type ChildBlock struct {+ ID string `json:"id"`+ Type string `json:"type"`+ SubType string `json:"subType,omitempty"`+ Content string `json:"content,omitempty"`+ Markdown string `json:"markdown,omitempty"`+}++type TailChildBlocksRequest struct {+ BlockQueryRequest+ N *float64 `json:"n" api:"optional"`+}++type CheckBlocksExistRequest struct {+ IDs []JSONValue `json:"ids"`+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`+ ID string `json:"id" api:"optional,nullable,ignoretype"`+}++type OrderedListStartData struct {+ Start int `json:"start"`+ Found bool `json:"found"`+}++type ContentWordCountRequest struct {+ Content string `json:"content"`+ ReqID JSONValue `json:"reqId" api:"optional,nullable"`+}++type BlocksWordCountRequest struct {+ BlocksQueryRequest+ ReqID JSONValue `json:"reqId" api:"optional,nullable"`+}++type WordCountData struct {+ ReqID JSONValue `json:"reqId"`+ Stat *BlockStat `json:"stat"`+}++type BlockStat struct {+ RuneCount int `json:"runeCount"`+ WordCount int `json:"wordCount"`+ LinkCount int `json:"linkCount"`+ ImageCount int `json:"imageCount"`+ RefCount int `json:"refCount"`+ BlockCount int `json:"blockCount"`+}++type BlockDOMData struct {+ ID string `json:"id"`+ DOM string `json:"dom"`+}++type BlockKramdownData struct {+ ID string `json:"id"`+ Kramdown string `json:"kramdown"`+}++type BlockKramdownRequest struct {+ BlockQueryRequest+ Mode *string `json:"mode" api:"optional"`+}++type BlocksKramdownRequest struct {+ BlocksQueryRequest+ Mode *string `json:"mode" api:"optional"`+}+type BlockQueryRequest struct {ID string `json:"id"`Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`diff --git a/kernel/apicontract/block_document.go b/kernel/apicontract/block_document.gonew file mode 100644index 0000000000..25873c5b85--- /dev/null+++ b/kernel/apicontract/block_document.go@@ -0,0 +1,50 @@+package apicontract++type DocInfo struct {+ ID string `json:"id"`+ RootID string `json:"rootID"`+ Name string `json:"name"`+ RefCount int `json:"refCount"`+ SubFileCount int `json:"subFileCount"`+ RefIDs []string `json:"refIDs"`+ IAL map[string]string `json:"ial"`+ Icon string `json:"icon"`+ AttrViews []*DocAttrView `json:"attrViews"`+}++type DocAttrView struct {+ ID string `json:"id"`+ Name string `json:"name"`+}++type DocsInfoRequest struct {+ IDs []string `json:"ids"`+ RefCount bool `json:"refCount"`+ AV bool `json:"av"`+}++type TreeStatRequest struct {+ BlockQueryRequest+ IncludeEmbed bool `json:"includeEmbed" api:"optional,nullable"`+ ReqID JSONValue `json:"reqId" api:"optional,nullable"`+}++type TreeStatData struct {+ ReqID JSONValue `json:"reqId"`+ Stat *BlockStat `json:"stat"`+ ContainsEmbed *bool `json:"containsEmbed,omitempty"`+ StatWithEmbed **BlockStat `json:"statWithEmbed,omitempty"`+ EmbedStat **EmbedStat `json:"embedStat,omitempty"`+}++type EmbedStat struct {+ Complete bool `json:"complete"`+ QueryEmbedCount int `json:"queryEmbedCount"`+ JSEmbedCount int `json:"jsEmbedCount"`+ ResultCount int `json:"resultCount"`+ FailedQueryCount int `json:"failedQueryCount"`+ FailedResultCount int `json:"failedResultCount"`+ TruncatedQueryCount int `json:"truncatedQueryCount"`+ CycleCount int `json:"cycleCount"`+ DepthLimitCount int `json:"depthLimitCount"`+}diff --git a/kernel/apicontract/block_edit.go b/kernel/apicontract/block_edit.gonew file mode 100644index 0000000000..d2ef898cbf--- /dev/null+++ b/kernel/apicontract/block_edit.go@@ -0,0 +1,25 @@+package apicontract++type MoveBlockRequest struct {+ ID string `json:"id"`+ ParentID *string `json:"parentID" api:"optional"`+ PreviousID *string `json:"previousID" api:"optional"`+}++type TransferBlockRefRequest struct {+ FromID string `json:"fromID"`+ ToID string `json:"toID"`+ ReloadUI *bool `json:"reloadUI" api:"optional"`+ RefIDs []string `json:"refIDs" api:"optional,nullable"`+}++type SwapBlockRefRequest struct {+ RefID string `json:"refID"`+ DefID string `json:"defID"`+ IncludeChildren bool `json:"includeChildren"`+}++type BlockReminderRequest struct {+ ID string `json:"id"`+ Timed string `json:"timed"`+}diff --git a/kernel/apicontract/block_edit_test.go b/kernel/apicontract/block_edit_test.gonew file mode 100644index 0000000000..4dea409134--- /dev/null+++ b/kernel/apicontract/block_edit_test.go@@ -0,0 +1,38 @@+package apicontract++import (+ "reflect"+ "strings"+ "testing"+)++func TestTransferBlockRefCompatibility(t *testing.T) {+ for _, body := range []string{`{"fromID":"from","toID":"to"}`, `{"fromID":"from","toID":"to","reloadUI":null,"refIDs":null}`} {+ request, err := TransferBlockRef.Decode(strings.NewReader(body))+ if err != nil || request.ReloadUI != nil || request.RefIDs != nil {+ t.Fatalf("reference transfer defaults changed: %+v, %v", request, err)+ }+ }+ request, err := TransferBlockRef.Decode(strings.NewReader(`{"fromID":"from","toID":"to","reloadUI":false,"refIDs":["ref","ref"]}`))+ if err != nil || request.ReloadUI == nil || *request.ReloadUI || !reflect.DeepEqual(request.RefIDs, []string{"ref", "ref"}) {+ t.Fatalf("reference transfer input changed: %+v, %v", request, err)+ }+ for _, body := range []string{`{"fromID":"from","toID":"to","reloadUI":0}`, `{"fromID":"from","toID":"to","refIDs":[null]}`} {+ if _, err := TransferBlockRef.Decode(strings.NewReader(body)); err == nil {+ t.Fatalf("invalid reference transfer accepted: %s", body)+ }+ }+}++func TestMoveBlockCompatibility(t *testing.T) {+ for _, body := range []string{`{"id":" raw "}`, `{"id":" raw ","parentID":null,"previousID":null}`} {+ request, err := MoveBlock.Decode(strings.NewReader(body))+ if err != nil || request.ID != " raw " || request.ParentID != nil || request.PreviousID != nil {+ t.Fatalf("move defaults changed: %+v, %v", request, err)+ }+ }+ request, err := MoveBlock.Decode(strings.NewReader(`{"id":"id","parentID":"","previousID":""}`))+ if err != nil || request.ParentID == nil || *request.ParentID != "" || request.PreviousID == nil || *request.PreviousID != "" {+ t.Fatalf("explicit empty move targets changed: %+v, %v", request, err)+ }+}diff --git a/kernel/apicontract/block_inputs.go b/kernel/apicontract/block_inputs.gonew file mode 100644index 0000000000..c95d4c22f4--- /dev/null+++ b/kernel/apicontract/block_inputs.go@@ -0,0 +1,67 @@+package apicontract++type TaskListMarkerRequest struct {+ ID string `json:"id" api:"trim"`+ Marker string `json:"marker"`+}++type BatchTaskListMarkerRequest struct {+ Items []TaskListMarkerRequest `json:"items"`+}++type DailyNoteBlockRequest struct {+ Data string `json:"data"`+ DataType string `json:"dataType"`+ Notebook string `json:"notebook"`+}++type AppendBlockRequest struct {+ Data string `json:"data"`+ DataType string `json:"dataType" api:"trim"`+ ParentID string `json:"parentID" api:"trim"`+}++type PrependBlockRequest struct {+ Data string `json:"data"`+ DataType string `json:"dataType"`+ ParentID string `json:"parentID"`+}++type BatchParentBlockRequest struct {+ Blocks []PrependBlockRequest `json:"blocks"`+}++type InsertBlockRequest struct {+ Data string `json:"data"`+ DataType string `json:"dataType" api:"trim"`+ ParentID string `json:"parentID" api:"optional,nullable"`+ PreviousID string `json:"previousID" api:"optional,nullable"`+ NextID string `json:"nextID" api:"optional,nullable"`+}++type BlockInsertInput struct {+ Data string `json:"data"`+ DataType string `json:"dataType"`+ ParentID string `json:"parentID" api:"optional,nullable"`+ PreviousID string `json:"previousID" api:"optional,nullable"`+ NextID string `json:"nextID" api:"optional,nullable"`+}++type BatchInsertBlockRequest struct {+ Blocks []BlockInsertInput `json:"blocks"`+}++type UpdateBlockRequest struct {+ ID string `json:"id" api:"trim"`+ Data string `json:"data"`+ DataType string `json:"dataType" api:"trim"`+ LockType bool `json:"lockType" api:"optional,nullable"`+}++type BatchUpdateBlockRequest struct {+ Blocks []UpdateBlockRequest `json:"blocks"`+}++type DeleteBlockRequest struct {+ ID string `json:"id" api:"trim"`+}diff --git a/kernel/apicontract/block_ref.go b/kernel/apicontract/block_ref.gonew file mode 100644index 0000000000..d824b99ce6--- /dev/null+++ b/kernel/apicontract/block_ref.go@@ -0,0 +1,31 @@+package apicontract++type RefDefs struct {+ RefID string `json:"refID"`+ DefIDs []string `json:"defIDs"`+}++type RefIDsData struct {+ RefDefs []*RefDefs `json:"refDefs"`+ OriginalRefBlockIDs map[string]string `json:"originalRefBlockIDs"`+}++type RefDefsData struct {+ RefDefs []RefDefs `json:"refDefs" api:"nonnullable"`+}++type RefIDsRequest struct {+ ID string `json:"id" api:"optional,nullable"`+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`+ IDs []string `json:"ids" api:"optional,filterstrings"`+}++type FileAnnotationRefRequest struct {+ ID string `json:"id"`+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`+}++type RefTextQueryRequest struct {+ Anchor string `json:"anchor"`+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`+}diff --git a/kernel/apicontract/block_transaction.go b/kernel/apicontract/block_transaction.gonew file mode 100644index 0000000000..2a4f65fc7b--- /dev/null+++ b/kernel/apicontract/block_transaction.go@@ -0,0 +1,134 @@+package apicontract++import (+ "bytes"+ "encoding/json"+ "fmt"+)++type BlockTransaction struct {+ Timestamp int64 `json:"timestamp"`+ DoOperations []*BlockOperation `json:"doOperations"`+ UndoOperations []*BlockOperation `json:"undoOperations"`+ TemplateDocTreePlanID string `json:"templateDocTreePlanID,omitempty"`+}++type HeadingFoldRequest struct {+ ID string `json:"id"`+ Scope string `json:"scope"`+}++type BlockDeleteData struct {+ CreateEmptyParagraph bool `json:"createEmptyParagraph"`+}++// BlockOperationData 区分块内容文本和删除文档内容时的空段落选项。+type BlockOperationData struct {+ text *string+ deleteOptions *BlockDeleteData+}++func (d BlockOperationData) MarshalJSON() ([]byte, error) {+ if d.text != nil {+ return json.Marshal(*d.text)+ }+ return json.Marshal(d.deleteOptions)+}++func (d *BlockOperationData) UnmarshalJSON(data []byte) error {+ data = bytes.TrimSpace(data)+ *d = BlockOperationData{}+ if bytes.Equal(data, []byte("null")) {+ return nil+ }+ if len(data) > 0 && data[0] == '"' {+ return json.Unmarshal(data, &d.text)+ }+ var options struct {+ CreateEmptyParagraph *bool `json:"createEmptyParagraph"`+ }+ decoder := json.NewDecoder(bytes.NewReader(data))+ decoder.DisallowUnknownFields()+ if err := decoder.Decode(&options); err != nil {+ return err+ }+ if options.CreateEmptyParagraph == nil {+ return fmt.Errorf("createEmptyParagraph must be a boolean")+ }+ d.deleteOptions = &BlockDeleteData{CreateEmptyParagraph: *options.CreateEmptyParagraph}+ return nil+}++// BlockOperationResult 保留块操作返回的文本、块 ID 数组和空值三种载荷。+type BlockOperationResult struct {+ text *string+ ids []string+}++func (r BlockOperationResult) MarshalJSON() ([]byte, error) {+ if r.text != nil {+ return json.Marshal(*r.text)+ }+ return json.Marshal(r.ids)+}++func (r *BlockOperationResult) UnmarshalJSON(data []byte) error {+ data = bytes.TrimSpace(data)+ *r = BlockOperationResult{}+ if bytes.Equal(data, []byte("null")) {+ return nil+ }+ if len(data) > 0 && data[0] == '"' {+ return json.Unmarshal(data, &r.text)+ }+ var values []json.RawMessage+ if len(data) == 0 || data[0] != '[' {+ return fmt.Errorf("block operation result must be text, block IDs or null")+ }+ if err := json.Unmarshal(data, &values); err != nil {+ return err+ }+ r.ids = make([]string, len(values))+ for i, value := range values {+ if bytes.Equal(bytes.TrimSpace(value), []byte("null")) {+ return fmt.Errorf("block ID must be text")+ }+ if err := json.Unmarshal(value, &r.ids[i]); err != nil {+ return err+ }+ }+ return nil+}++type BlockOperation struct {+ Action string `json:"action" api:"enum=delete|insert|update|foldHeading|unfoldHeading|setAttrs|moveOutlineHeading|appendInsert|prependInsert"`+ Data BlockOperationData `json:"data"`+ ID string `json:"id"`+ RootID string `json:"rootID"`+ ParentID string `json:"parentID"`+ PreviousID string `json:"previousID"`+ NextID string `json:"nextID"`+ RetData BlockOperationResult `json:"retData"`+ BlockIDs []string `json:"blockIDs"`+ BlockID string `json:"blockID"`+ DeckID string `json:"deckID"`+ AvID string `json:"avID"`+ SrcIDs []string `json:"srcIDs"`+ Srcs Null `json:"srcs"`+ IsDetached bool `json:"isDetached"`+ Name string `json:"name"`+ Typ string `json:"type" api:"const=\"\""`+ Format string `json:"format"`+ KeyID string `json:"keyID"`+ RowID string `json:"rowID"`+ IsTwoWay bool `json:"isTwoWay"`+ BackRelationKeyID string `json:"backRelationKeyID"`+ RemoveDest bool `json:"removeDest"`+ Layout string `json:"layout"`+ GroupID string `json:"groupID"`+ TargetGroupID string `json:"targetGroupID"`+ ViewID string `json:"viewID"`+ ViewIDs []string `json:"viewIDs,omitempty"`+ IgnoreDefaultFill bool `json:"ignoreDefaultFill"`+ Context map[string]string `json:"context"`+}diff --git a/kernel/apicontract/block_transaction_test.go b/kernel/apicontract/block_transaction_test.gonew file mode 100644index 0000000000..5ac5ddcf5d--- /dev/null+++ b/kernel/apicontract/block_transaction_test.go@@ -0,0 +1,44 @@+package apicontract++import (+ "encoding/json"+ "testing"+)++func TestBlockOperationResult(t *testing.T) {+ for _, text := range []string{`null`, `""`, `"text"`, `[]`, `["a","b"]`} {+ var result BlockOperationResult+ if err := json.Unmarshal([]byte(text), &result); err != nil {+ t.Fatal(err)+ }+ data, err := json.Marshal(result)+ if err != nil || string(data) != text {+ t.Fatalf("block operation result changed: %s != %s, %v", text, data, err)+ }+ }+ for _, text := range []string{`1`, `true`, `{}`, `[null]`, `[1]`, `[["a"]]`} {+ var result BlockOperationResult+ if err := json.Unmarshal([]byte(text), &result); err == nil {+ t.Fatalf("invalid block operation result accepted: %s", text)+ }+ }+}++func TestBlockOperationData(t *testing.T) {+ for _, text := range []string{`null`, `""`, `"text"`, `{"createEmptyParagraph":false}`, `{"createEmptyParagraph":true}`} {+ var value BlockOperationData+ if err := json.Unmarshal([]byte(text), &value); err != nil {+ t.Fatal(err)+ }+ data, err := json.Marshal(value)+ if err != nil || string(data) != text {+ t.Fatalf("operation data changed: %s != %s, %v", text, data, err)+ }+ }+ for _, text := range []string{`[]`, `1`, `true`, `{}`, `{"createEmptyParagraph":null}`, `{"createEmptyParagraph":false,"other":true}`} {+ var value BlockOperationData+ if err := json.Unmarshal([]byte(text), &value); err == nil {+ t.Fatalf("invalid operation data accepted: %s", text)+ }+ }+}diff --git a/kernel/apicontract/block_tree.go b/kernel/apicontract/block_tree.gonew file mode 100644index 0000000000..cee74c006d--- /dev/null+++ b/kernel/apicontract/block_tree.go@@ -0,0 +1,37 @@+package apicontract++type BlockTreeInfo struct {+ ID string `json:"id"`+ Type string `json:"type"`+ ParentID string `json:"parentID"`+ ParentType string `json:"parentType"`+ PreviousID string `json:"previousID"`+ PreviousType string `json:"previousType"`+ NextID string `json:"nextID"`+ NextType string `json:"nextType"`+}++type BlockPath struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Type string `json:"type"`+ SubType string `json:"subType"`+ Children []*BlockPath `json:"children"`+ HasChildren bool `json:"hasChildren,omitempty"`+}++type BlockBreadcrumbChildren struct {+ Items []*BlockPath `json:"items"`+ HasMore bool `json:"hasMore"`+}++type BlockBreadcrumbRequest struct {+ BlockQueryRequest+ ExcludeTypes []string `json:"excludeTypes" api:"optional,nullable"`+}++type BlockBreadcrumbChildrenRequest struct {+ BlockBreadcrumbRequest+ Offset *float64 `json:"offset" api:"optional"`+ Limit *float64 `json:"limit" api:"optional"`+}diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.goindex ed62d0a90a..c06ada7699 100644--- a/kernel/apicontract/contracts.go+++ b/kernel/apicontract/contracts.go@@ -7,6 +7,8 @@ type BodyMode stringconst (JSONBody BodyMode = "json"+ MultipartBody BodyMode = "multipart"+ StructJSONBody BodyMode = "structJSON"NoBody BodyMode = "none"LegacyOptionalBody BodyMode = "legacyOptional")@@ -21,6 +23,7 @@ type Definition struct {ErrorCodes []intErrorText boolDataNonNullable bool+ DataOnError bool}type Endpoint[Request, Data any] struct {@@ -31,10 +34,42 @@ type ResponseOptions struct {AdditionalCodes []intText boolNonNullable bool+ DataOnError bool}var definitions []Definition+var (+ GetChildBlocks = define[BlockQueryRequest, []*ChildBlock]("getChildBlocks", "/api/block/getChildBlocks", JSONBody, ResponseOptions{NonNullable: true}, "POST")+ GetTailChildBlocks = define[TailChildBlocksRequest, []*ChildBlock]("getTailChildBlocks", "/api/block/getTailChildBlocks", JSONBody, ResponseOptions{NonNullable: true}, "POST")+)++var (+ CheckBlocksExist = define[CheckBlocksExistRequest, map[string]bool]("checkBlocksExist", "/api/block/checkBlocksExist", JSONBody, ResponseOptions{}, "POST")+ GetOrderedListContinueStart = define[BlockQueryRequest, OrderedListStartData]("getOrderedListContinueStart", "/api/block/getOrderedListContinueStart", JSONBody, ResponseOptions{}, "POST")+)++var (+ GetContentWordCount = define[ContentWordCountRequest, WordCountData]("getContentWordCount", "/api/block/getContentWordCount", JSONBody, ResponseOptions{}, "POST")+ GetBlocksWordCount = define[BlocksWordCountRequest, WordCountData]("getBlocksWordCount", "/api/block/getBlocksWordCount", JSONBody, ResponseOptions{}, "POST")+)++var SetNotebookConf = define[SetNotebookConfRequest, *NotebookConf]("setNotebookConf", "/api/notebook/setNotebookConf", JSONBody, ResponseOptions{}, "POST")++var ReorderNotebooks = define[ReorderNotebooksRequest, *ReorderData]("reorderNotebooks", "/api/notebook/reorder", StructJSONBody, ResponseOptions{DataOnError: true}, "POST")++var (+ OpenNotebook = define[OpenNotebookRequest, Null]("openNotebook", "/api/notebook/openNotebook", JSONBody, ResponseOptions{}, "POST")+ GetNotebookConf = define[CloseNotebookRequest, NotebookConfData]("getNotebookConf", "/api/notebook/getNotebookConf", JSONBody, ResponseOptions{}, "POST")+)++var ImportNotebookCryptoBackup = define[ImportNotebookCryptoBackupRequest, Null]("importNotebookCryptoBackup", "/api/notebook/importNotebookCryptoBackup", MultipartBody, ResponseOptions{}, "POST")++var (+ GetNotebookInfo = define[NotebookIDRequest, NotebookInfoData]("getNotebookInfo", "/api/notebook/getNotebookInfo", JSONBody, ResponseOptions{}, "POST")+ GetEncryptedNotebookStatus = define[EmptyRequest, EncryptedNotebookStatusData]("getEncryptedNotebookStatus", "/api/notebook/getEncryptedNotebookStatus", NoBody, ResponseOptions{}, "POST")+)+var (SetNotebookIcon = define[SetNotebookIconRequest, Null]("setNotebookIcon", "/api/notebook/setNotebookIcon", JSONBody, ResponseOptions{}, "POST")ChangeSortNotebook = define[ChangeSortNotebookRequest, Null]("changeSortNotebook", "/api/notebook/changeSortNotebook", JSONBody, ResponseOptions{}, "POST")@@ -52,7 +87,7 @@ var (func define[Request, Data any](name, path string, body BodyMode, response ResponseOptions, methods ...string) Endpoint[Request, Data] {d := Definition{Name: name, Path: path, Methods: methods, Body: body,Request: reflect.TypeFor[Request](), Data: reflect.TypeFor[Data](),- ErrorCodes: append([]int{-1}, response.AdditionalCodes...), ErrorText: response.Text, DataNonNullable: response.NonNullable}+ ErrorCodes: append([]int{-1}, response.AdditionalCodes...), ErrorText: response.Text, DataNonNullable: response.NonNullable, DataOnError: response.DataOnError}definitions = append(definitions, d)return Endpoint[Request, Data]{definition: d}}@@ -220,3 +255,90 @@ var (AppendHeadingChildren = define[AppendHeadingChildrenRequest, Null]("appendHeadingChildren", "/api/block/appendHeadingChildren", JSONBody, ResponseOptions{}, "POST")GetDocBlocksOrders = define[DocOrdersRequest, []string]("getDocBlocksOrders", "/api/block/getDocBlocksOrders", JSONBody, ResponseOptions{}, "POST"))++var (+ EnableEncryptedNotebooks = define[NotebookPasswordRequest, Null]("enableEncryptedNotebooks", "/api/notebook/enableEncryptedNotebooks", JSONBody, ResponseOptions{}, "POST")+ DisableEncryptedNotebooks = define[EmptyRequest, Null]("disableEncryptedNotebooks", "/api/notebook/disableEncryptedNotebooks", NoBody, ResponseOptions{}, "POST")+ CreateEncryptedNotebook = define[CreateEncryptedNotebookRequest, CreateNotebookData]("createEncryptedNotebook", "/api/notebook/createEncryptedNotebook", JSONBody, ResponseOptions{}, "POST")+ UnlockNotebook = define[UnlockNotebookRequest, Null]("unlockNotebook", "/api/notebook/unlockNotebook", JSONBody, ResponseOptions{}, "POST")+ UnlockAndOpenNotebook = define[UnlockNotebookRequest, Null]("unlockAndOpenNotebook", "/api/notebook/unlockAndOpenNotebook", JSONBody, ResponseOptions{}, "POST")+ LockNotebook = define[NotebookIDRequest, Null]("lockNotebook", "/api/notebook/lockNotebook", JSONBody, ResponseOptions{}, "POST")+ SetNotebookCryptoAutoLock = define[NotebookCryptoAutoLockRequest, Null]("setNotebookCryptoAutoLock", "/api/notebook/setNotebookCryptoAutoLock", JSONBody, ResponseOptions{}, "POST")+ ChangeMasterPassword = define[ChangeMasterPasswordRequest, Null]("changeMasterPassword", "/api/notebook/changeMasterPassword", JSONBody, ResponseOptions{}, "POST")+ ExportNotebookCryptoBackup = define[EmptyRequest, NotebookCryptoBackupData]("exportNotebookCryptoBackup", "/api/notebook/exportNotebookCryptoBackup", NoBody, ResponseOptions{}, "POST")+ TouchEncryptedNotebooks = define[EmptyRequest, Null]("touchEncryptedNotebooks", "/api/notebook/touchEncryptedNotebooks", NoBody, ResponseOptions{}, "POST")+)++var (+ GetBlockDOM = define[BlockQueryRequest, BlockDOMData]("getBlockDOM", "/api/block/getBlockDOM", JSONBody, ResponseOptions{}, "POST")+ GetBlockDOMWithEmbed = define[BlockQueryRequest, BlockDOMData]("getBlockDOMWithEmbed", "/api/block/getBlockDOMWithEmbed", JSONBody, ResponseOptions{}, "POST")+ GetBlockDOMs = define[BlocksQueryRequest, map[string]string]("getBlockDOMs", "/api/block/getBlockDOMs", JSONBody, ResponseOptions{}, "POST")+ GetBlockDOMsWithEmbed = define[BlocksQueryRequest, map[string]string]("getBlockDOMsWithEmbed", "/api/block/getBlockDOMsWithEmbed", JSONBody, ResponseOptions{}, "POST")+ GetBlockKramdown = define[BlockKramdownRequest, BlockKramdownData]("getBlockKramdown", "/api/block/getBlockKramdown", JSONBody, ResponseOptions{}, "POST")+ GetBlockKramdowns = define[BlocksKramdownRequest, map[string]string]("getBlockKramdowns", "/api/block/getBlockKramdowns", JSONBody, ResponseOptions{}, "POST")+)++var (+ GetRefText = define[BlockQueryRequest, string]("getRefText", "/api/block/getRefText", JSONBody, ResponseOptions{}, "POST")+ GetRefIDs = define[RefIDsRequest, RefIDsData]("getRefIDs", "/api/block/getRefIDs", JSONBody, ResponseOptions{}, "POST")+ GetRefIDsByFileAnnotationID = define[FileAnnotationRefRequest, RefDefsData]("getRefIDsByFileAnnotationID", "/api/block/getRefIDsByFileAnnotationID", JSONBody, ResponseOptions{}, "POST")+ GetBlockDefIDsByRefText = define[RefTextQueryRequest, RefDefsData]("getBlockDefIDsByRefText", "/api/block/getBlockDefIDsByRefText", JSONBody, ResponseOptions{}, "POST")+)++var (+ GetBlockTreeInfos = define[BlocksQueryRequest, map[string]*BlockTreeInfo]("getBlockTreeInfos", "/api/block/getBlockTreeInfos", JSONBody, ResponseOptions{}, "POST")+ GetBlockBreadcrumb = define[BlockBreadcrumbRequest, []*BlockPath]("getBlockBreadcrumb", "/api/block/getBlockBreadcrumb", JSONBody, ResponseOptions{}, "POST")+ GetBlockBreadcrumbChildren = define[BlockBreadcrumbChildrenRequest, *BlockBreadcrumbChildren]("getBlockBreadcrumbChildren", "/api/block/getBlockBreadcrumbChildren", JSONBody, ResponseOptions{}, "POST")+)++var GetDocInfo = define[BlockQueryRequest, *DocInfo]("getDocInfo", "/api/block/getDocInfo", JSONBody, ResponseOptions{}, "POST")++var GetDocsInfo = define[DocsInfoRequest, []*DocInfo]("getDocsInfo", "/api/block/getDocsInfo", JSONBody, ResponseOptions{}, "POST")++var GetTreeStat = define[TreeStatRequest, TreeStatData]("getTreeStat", "/api/block/getTreeStat", JSONBody, ResponseOptions{}, "POST")++var TransferBlockRef = define[TransferBlockRefRequest, Null]("transferBlockRef", "/api/block/transferBlockRef", JSONBody, ResponseOptions{}, "POST")++var SwapBlockRef = define[SwapBlockRefRequest, Null]("swapBlockRef", "/api/block/swapBlockRef", JSONBody, ResponseOptions{}, "POST")++var SetBlockReminder = define[BlockReminderRequest, Null]("setBlockReminder", "/api/block/setBlockReminder", JSONBody, ResponseOptions{}, "POST")++var UnfoldBlock = define[BlockIDRequest, Null]("unfoldBlock", "/api/block/unfoldBlock", JSONBody, ResponseOptions{}, "POST")++var FoldBlock = define[BlockIDRequest, Null]("foldBlock", "/api/block/foldBlock", JSONBody, ResponseOptions{}, "POST")++var MoveBlock = define[MoveBlockRequest, Null]("moveBlock", "/api/block/moveBlock", JSONBody, ResponseOptions{}, "POST")++var GetHeadingDeleteTransaction = define[BlockIDRequest, *BlockTransaction]("getHeadingDeleteTransaction", "/api/block/getHeadingDeleteTransaction", JSONBody, ResponseOptions{}, "POST")++var GetHeadingInsertTransaction = define[BlockIDRequest, *BlockTransaction]("getHeadingInsertTransaction", "/api/block/getHeadingInsertTransaction", JSONBody, ResponseOptions{}, "POST")++var GetHeadingFoldTransaction = define[HeadingFoldRequest, *BlockTransaction]("getHeadingFoldTransaction", "/api/block/getHeadingFoldTransaction", JSONBody, ResponseOptions{}, "POST")++var UpdateTaskListItemMarker = define[TaskListMarkerRequest, []*BlockTransaction]("updateTaskListItemMarker", "/api/block/updateTaskListItemMarker", JSONBody, ResponseOptions{}, "POST")++var BatchUpdateTaskListItemMarker = define[BatchTaskListMarkerRequest, []*BlockTransaction]("batchUpdateTaskListItemMarker", "/api/block/batchUpdateTaskListItemMarker", JSONBody, ResponseOptions{}, "POST")++var MoveOutlineHeading = define[MoveBlockRequest, []*BlockTransaction]("moveOutlineHeading", "/api/block/moveOutlineHeading", JSONBody, ResponseOptions{}, "POST")++var AppendDailyNoteBlock = define[DailyNoteBlockRequest, []*BlockTransaction]("appendDailyNoteBlock", "/api/block/appendDailyNoteBlock", JSONBody, ResponseOptions{}, "POST")++var PrependDailyNoteBlock = define[DailyNoteBlockRequest, []*BlockTransaction]("prependDailyNoteBlock", "/api/block/prependDailyNoteBlock", JSONBody, ResponseOptions{}, "POST")++var AppendBlock = define[AppendBlockRequest, []*BlockTransaction]("appendBlock", "/api/block/appendBlock", JSONBody, ResponseOptions{}, "POST")++var PrependBlock = define[PrependBlockRequest, []*BlockTransaction]("prependBlock", "/api/block/prependBlock", JSONBody, ResponseOptions{}, "POST")++var BatchAppendBlock = define[BatchParentBlockRequest, []*BlockTransaction]("batchAppendBlock", "/api/block/batchAppendBlock", JSONBody, ResponseOptions{}, "POST")++var BatchPrependBlock = define[BatchParentBlockRequest, []*BlockTransaction]("batchPrependBlock", "/api/block/batchPrependBlock", JSONBody, ResponseOptions{}, "POST")++var InsertBlock = define[InsertBlockRequest, []*BlockTransaction]("insertBlock", "/api/block/insertBlock", JSONBody, ResponseOptions{}, "POST")++var BatchInsertBlock = define[BatchInsertBlockRequest, []*BlockTransaction]("batchInsertBlock", "/api/block/batchInsertBlock", JSONBody, ResponseOptions{}, "POST")++var UpdateBlock = define[UpdateBlockRequest, []*BlockTransaction]("updateBlock", "/api/block/updateBlock", JSONBody, ResponseOptions{}, "POST")++var BatchUpdateBlock = define[BatchUpdateBlockRequest, []*BlockTransaction]("batchUpdateBlock", "/api/block/batchUpdateBlock", JSONBody, ResponseOptions{}, "POST")++var DeleteBlock = define[DeleteBlockRequest, []*BlockTransaction]("deleteBlock", "/api/block/deleteBlock", JSONBody, ResponseOptions{}, "POST")diff --git a/kernel/apicontract/decode.go b/kernel/apicontract/decode.goindex a26d2b6327..9ea5324a75 100644--- a/kernel/apicontract/decode.go+++ b/kernel/apicontract/decode.go@@ -18,6 +18,13 @@ func (e Endpoint[Request, Data]) Decode(reader io.Reader) (request Request, errif reader == nil {reader = bytes.NewReader(nil)}+ if e.definition.Body == StructJSONBody {+ err = json.NewDecoder(reader).Decode(&request)+ if err != nil {+ err = fmt.Errorf("Parses request [%s] failed: %s", e.definition.Path, err)+ }+ return+ }var fields map[string]json.RawMessageerr = json.NewDecoder(reader).Decode(&fields)if err != nil {@@ -83,6 +90,17 @@ func decodeRequestFields(value reflect.Value, fields map[string]json.RawMessage)var decodeErr errorif isNull && has("nullable") {value.Field(i).SetZero()+ } else if has("legacyobject") {+ // 配置补丁先按 JSON 数字语义归一化,再按结构体字段名兼容绑定。+ var normalized any+ decodeErr = json.Unmarshal(raw, &normalized)+ if decodeErr == nil {+ var data []byte+ data, decodeErr = json.Marshal(normalized)+ if decodeErr == nil {+ decodeErr = json.Unmarshal(data, value.Field(i).Addr().Interface())+ }+ }} else {decodeErr = decodeRequestValue(raw, value.Field(i))}@@ -138,6 +156,9 @@ func decodeRequestFields(value reflect.Value, fields map[string]json.RawMessage)// decodeRequestValue 递归绑定复合参数,避免数组元素和嵌套字段绕过空值及必填检查。func decodeRequestValue(raw json.RawMessage, value reflect.Value) error {+ if value.Type() == reflect.TypeFor[JSONValue]() {+ return json.Unmarshal(raw, value.Addr().Interface())+ }if bytes.Equal(bytes.TrimSpace(raw), []byte("null")) {switch value.Kind() {case reflect.Pointer, reflect.Map, reflect.Slice:diff --git a/kernel/apicontract/json_value.go b/kernel/apicontract/json_value.gonew file mode 100644index 0000000000..cf83d487e7--- /dev/null+++ b/kernel/apicontract/json_value.go@@ -0,0 +1,33 @@+package apicontract++import "encoding/json"++// JSONValue 仅用于协议明确允许任意 JSON 的透传字段,零值表示 null。+type JSONValue struct{ raw json.RawMessage }++func (v JSONValue) StringValue() (value string, ok bool) {+ if len(v.raw) == 0 || v.raw[0] != '"' {+ return "", false+ }+ err := json.Unmarshal(v.raw, &value)+ return value, err == nil+}++func (v JSONValue) MarshalJSON() ([]byte, error) {+ if len(v.raw) == 0 {+ return []byte("null"), nil+ }+ return v.raw, nil+}++func (v *JSONValue) UnmarshalJSON(data []byte) error {+ var value any+ if err := json.Unmarshal(data, &value); err != nil {+ return err+ }+ normalized, err := json.Marshal(value)+ if err == nil {+ v.raw = normalized+ }+ return err+}diff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.jsonindex 71ac070273..032eb4e8d8 100644--- a/kernel/apicontract/legacy_routes.json+++ b/kernel/apicontract/legacy_routes.json@@ -159,55 +159,10 @@{"method":"POST","path":"/api/bazaar/uninstallBazaarTheme","handler":"uninstallBazaarTheme"},{"method":"POST","path":"/api/bazaar/uninstallBazaarWidget","handler":"uninstallBazaarWidget"},{"method":"POST","path":"/api/bazaar/updateBazaarPackage","handler":"updateBazaarPackage"},- {"method":"POST","path":"/api/block/appendBlock","handler":"appendBlock"},- {"method":"POST","path":"/api/block/appendDailyNoteBlock","handler":"appendDailyNoteBlock"},- {"method":"POST","path":"/api/block/batchAppendBlock","handler":"batchAppendBlock"},- {"method":"POST","path":"/api/block/batchInsertBlock","handler":"batchInsertBlock"},- {"method":"POST","path":"/api/block/batchPrependBlock","handler":"batchPrependBlock"},- {"method":"POST","path":"/api/block/batchUpdateBlock","handler":"batchUpdateBlock"},- {"method":"POST","path":"/api/block/batchUpdateTaskListItemMarker","handler":"batchUpdateTaskListItemMarker"},{"method":"POST","path":"/api/block/checkBlockRef","handler":"checkBlockRef"},- {"method":"POST","path":"/api/block/checkBlocksExist","handler":"checkBlocksExist"},- {"method":"POST","path":"/api/block/deleteBlock","handler":"deleteBlock"},- {"method":"POST","path":"/api/block/foldBlock","handler":"foldBlock"},- {"method":"POST","path":"/api/block/getBlockBreadcrumb","handler":"getBlockBreadcrumb"},- {"method":"POST","path":"/api/block/getBlockBreadcrumbChildren","handler":"getBlockBreadcrumbChildren"},- {"method":"POST","path":"/api/block/getBlockDOM","handler":"getBlockDOM"},- {"method":"POST","path":"/api/block/getBlockDOMWithEmbed","handler":"getBlockDOMWithEmbed"},- {"method":"POST","path":"/api/block/getBlockDOMs","handler":"getBlockDOMs"},- {"method":"POST","path":"/api/block/getBlockDOMsWithEmbed","handler":"getBlockDOMsWithEmbed"},- {"method":"POST","path":"/api/block/getBlockDefIDsByRefText","handler":"getBlockDefIDsByRefText"},- {"method":"POST","path":"/api/block/getBlockKramdown","handler":"getBlockKramdown"},- {"method":"POST","path":"/api/block/getBlockKramdowns","handler":"getBlockKramdowns"},- {"method":"POST","path":"/api/block/getBlockTreeInfos","handler":"getBlockTreeInfos"},- {"method":"POST","path":"/api/block/getBlocksWordCount","handler":"getBlocksWordCount"},- {"method":"POST","path":"/api/block/getChildBlocks","handler":"getChildBlocks"},- {"method":"POST","path":"/api/block/getContentWordCount","handler":"getContentWordCount"},{"method":"POST","path":"/api/block/getDocHeadingLevelTransaction","handler":"getDocHeadingLevelTransaction"},- {"method":"POST","path":"/api/block/getDocInfo","handler":"getDocInfo"},- {"method":"POST","path":"/api/block/getDocsInfo","handler":"getDocsInfo"},- {"method":"POST","path":"/api/block/getHeadingDeleteTransaction","handler":"getHeadingDeleteTransaction"},- {"method":"POST","path":"/api/block/getHeadingFoldTransaction","handler":"getHeadingFoldTransaction"},- {"method":"POST","path":"/api/block/getHeadingInsertTransaction","handler":"getHeadingInsertTransaction"},{"method":"POST","path":"/api/block/getHeadingLevelTransaction","handler":"getHeadingLevelTransaction"},- {"method":"POST","path":"/api/block/getOrderedListContinueStart","handler":"getOrderedListContinueStart"},{"method":"POST","path":"/api/block/getRecentUpdatedBlocks","handler":"getRecentUpdatedBlocks"},- {"method":"POST","path":"/api/block/getRefIDs","handler":"getRefIDs"},- {"method":"POST","path":"/api/block/getRefIDsByFileAnnotationID","handler":"getRefIDsByFileAnnotationID"},- {"method":"POST","path":"/api/block/getRefText","handler":"getRefText"},- {"method":"POST","path":"/api/block/getTailChildBlocks","handler":"getTailChildBlocks"},- {"method":"POST","path":"/api/block/getTreeStat","handler":"getTreeStat"},- {"method":"POST","path":"/api/block/insertBlock","handler":"insertBlock"},- {"method":"POST","path":"/api/block/moveBlock","handler":"moveBlock"},- {"method":"POST","path":"/api/block/moveOutlineHeading","handler":"moveOutlineHeading"},- {"method":"POST","path":"/api/block/prependBlock","handler":"prependBlock"},- {"method":"POST","path":"/api/block/prependDailyNoteBlock","handler":"prependDailyNoteBlock"},- {"method":"POST","path":"/api/block/setBlockReminder","handler":"setBlockReminder"},- {"method":"POST","path":"/api/block/swapBlockRef","handler":"swapBlockRef"},- {"method":"POST","path":"/api/block/transferBlockRef","handler":"transferBlockRef"},- {"method":"POST","path":"/api/block/unfoldBlock","handler":"unfoldBlock"},- {"method":"POST","path":"/api/block/updateBlock","handler":"updateBlock"},- {"method":"POST","path":"/api/block/updateTaskListItemMarker","handler":"updateTaskListItemMarker"},{"method":"POST","path":"/api/bookmark/getBookmark","handler":"getBookmark"},{"method":"POST","path":"/api/broadcast/getChannelInfo","handler":"getChannelInfo"},{"method":"POST","path":"/api/broadcast/getChannels","handler":"getChannels"},@@ -340,23 +295,6 @@{"method":"POST","path":"/api/lute/spinBlockDOM","handler":"spinBlockDOM"},{"method":"POST","path":"/api/lute/wpsPresentation2BlockDOM","handler":"wpsPresentation2BlockDOM"},{"method":"POST","path":"/api/network/forwardProxy","handler":"forwardProxy"},- {"method":"POST","path":"/api/notebook/changeMasterPassword","handler":"changeMasterPassword"},- {"method":"POST","path":"/api/notebook/createEncryptedNotebook","handler":"createEncryptedNotebook"},- {"method":"POST","path":"/api/notebook/disableEncryptedNotebooks","handler":"disableEncryptedNotebooks"},- {"method":"POST","path":"/api/notebook/enableEncryptedNotebooks","handler":"enableEncryptedNotebooks"},- {"method":"POST","path":"/api/notebook/exportNotebookCryptoBackup","handler":"exportNotebookCryptoBackup"},- {"method":"POST","path":"/api/notebook/getEncryptedNotebookStatus","handler":"getEncryptedNotebookStatus"},- {"method":"POST","path":"/api/notebook/getNotebookConf","handler":"getNotebookConf"},- {"method":"POST","path":"/api/notebook/getNotebookInfo","handler":"getNotebookInfo"},- {"method":"POST","path":"/api/notebook/importNotebookCryptoBackup","handler":"importNotebookCryptoBackup"},- {"method":"POST","path":"/api/notebook/lockNotebook","handler":"lockNotebook"},- {"method":"POST","path":"/api/notebook/openNotebook","handler":"openNotebook"},- {"method":"POST","path":"/api/notebook/reorder","handler":"reorderNotebooks"},- {"method":"POST","path":"/api/notebook/setNotebookConf","handler":"setNotebookConf"},- {"method":"POST","path":"/api/notebook/setNotebookCryptoAutoLock","handler":"setNotebookCryptoAutoLock"},- {"method":"POST","path":"/api/notebook/touchEncryptedNotebooks","handler":"touchEncryptedNotebooks"},- {"method":"POST","path":"/api/notebook/unlockAndOpenNotebook","handler":"unlockAndOpenNotebook"},- {"method":"POST","path":"/api/notebook/unlockNotebook","handler":"unlockNotebook"},{"method":"POST","path":"/api/notification/pushErrMsg","handler":"pushErrMsg"},{"method":"POST","path":"/api/notification/pushMsg","handler":"pushMsg"},{"method":"POST","path":"/api/outline/getDocHeadingNumbers","handler":"getDocHeadingNumbers"},diff --git a/kernel/apicontract/multipart.go b/kernel/apicontract/multipart.gonew file mode 100644index 0000000000..7f7563f999--- /dev/null+++ b/kernel/apicontract/multipart.go@@ -0,0 +1,71 @@+package apicontract++import (+ "fmt"+ "mime/multipart"+ "reflect"+ "strings"+)++func validateMultipartRequest(t reflect.Type) error {+ for i := 0; i < t.NumField(); i++ {+ field := t.Field(i)+ if !field.IsExported() || field.Anonymous || field.Tag.Get("json") == "" {+ return fmt.Errorf("multipart fields must be named and exported: %s", field.Name)+ }+ if field.Type != reflect.TypeFor[string]() && field.Type != reflect.TypeFor[*multipart.FileHeader]() {+ return fmt.Errorf("unsupported multipart field: %s", field.Name)+ }+ for _, option := range strings.Split(field.Tag.Get("api"), ",") {+ if option != "" && option != "optional" && option != "nonnullable" {+ return fmt.Errorf("unsupported multipart option: %s", option)+ }+ }+ }+ return nil+}++// DecodeMultipart 保留表单重复字段取首值的行为,文件内容由业务入口按需读取。+func (e Endpoint[Request, Data]) DecodeMultipart(form *multipart.Form) (request Request, err error) {+ if e.definition.Body != MultipartBody {+ return request, fmt.Errorf("endpoint does not accept multipart data")+ }+ if form == nil {+ return request, fmt.Errorf("multipart form is missing")+ }+ value := reflect.ValueOf(&request).Elem()+ if value.Kind() != reflect.Struct {+ return request, fmt.Errorf("multipart request must be a struct")+ }+ if err = validateMultipartRequest(value.Type()); err != nil {+ return+ }+ for i := 0; i < value.NumField(); i++ {+ field := value.Type().Field(i)+ name := strings.Split(field.Tag.Get("json"), ",")[0]+ optional := strings.Contains(","+field.Tag.Get("api")+",", ",optional,")+ switch field.Type {+ case reflect.TypeFor[*multipart.FileHeader]():+ files := form.File[name]+ if len(files) == 0 {+ if !optional {+ return request, fmt.Errorf("%s not found", name)+ }+ continue+ }+ value.Field(i).Set(reflect.ValueOf(files[0]))+ case reflect.TypeFor[string]():+ values := form.Value[name]+ if len(values) == 0 {+ if !optional {+ return request, fmt.Errorf("Field [%s] is required", name)+ }+ continue+ }+ value.Field(i).SetString(values[0])+ default:+ return request, fmt.Errorf("unsupported multipart field: %s", name)+ }+ }+ return+}diff --git a/kernel/apicontract/multipart_test.go b/kernel/apicontract/multipart_test.gonew file mode 100644index 0000000000..8e84294857--- /dev/null+++ b/kernel/apicontract/multipart_test.go@@ -0,0 +1,33 @@+package apicontract++import (+ "mime/multipart"+ "reflect"+ "testing"+)++func TestMultipartRequestCompatibility(t *testing.T) {+ first := &multipart.FileHeader{Filename: "first.json"}+ form := &multipart.Form{+ File: map[string][]*multipart.FileHeader{"file": {first, {Filename: "second.json"}}},+ Value: map[string][]string{"password": {" secret ", "ignored"}},+ }+ request, err := ImportNotebookCryptoBackup.DecodeMultipart(form)+ if err != nil || request.File != first || request.Password != " secret " {+ t.Fatalf("multipart first-value semantics changed: %v", err)+ }+ delete(form.Value, "password")+ request, err = ImportNotebookCryptoBackup.DecodeMultipart(form)+ if err != nil || request.Password != "" {+ t.Fatalf("missing password must remain empty: %v", err)+ }+ delete(form.File, "file")+ if _, err = ImportNotebookCryptoBackup.DecodeMultipart(form); err == nil || err.Error() != "file not found" {+ t.Fatalf("missing file error changed: %v", err)+ }+ if err := validateMultipartRequest(reflect.TypeFor[struct {+ Count int `json:"count"`+ }]()); err == nil {+ t.Fatal("unsupported form field accepted")+ }+}diff --git a/kernel/apicontract/notebook.go b/kernel/apicontract/notebook.goindex ad8fa1bdbb..040f867ea2 100644--- a/kernel/apicontract/notebook.go+++ b/kernel/apicontract/notebook.go@@ -1,5 +1,120 @@package apicontract+import "mime/multipart"++type ReorderNotebooksRequest struct {+ SourceIDs []string `json:"sourceIDs" api:"optional,nullable"`+ TargetID string `json:"targetID" api:"optional,nullable"`+ Position string `json:"position" api:"optional,nullable"`+}++type ReorderData struct {+ Changed bool `json:"changed"`+ Notebook string `json:"notebook,omitempty"`+ ParentPath string `json:"parentPath,omitempty"`+}++type OpenNotebookRequest struct {+ NotebookIDRequest+ App string `json:"app" api:"optional,nullable,ignoretype"`+}++type NotebookEncryption struct {+ Spec int `json:"spec"`+ WrappedDEK *string `json:"wrappedDEK"`+ WrapNonce *string `json:"wrapNonce"`+ Metadata string `json:"metadata,omitempty"`+ CreatedAt int64 `json:"createdAt"`+}++type NotebookConf struct {+ Name string `json:"name"`+ Sort int `json:"sort"`+ Icon string `json:"icon"`+ Closed bool `json:"closed"`+ RefCreateSaveBox string `json:"refCreateSaveBox"`+ RefCreateSavePath string `json:"refCreateSavePath"`+ DocCreateSaveBox string `json:"docCreateSaveBox"`+ DocCreateSavePath string `json:"docCreateSavePath"`+ DocCreateTemplatePath string `json:"docCreateTemplatePath"`+ DailyNoteSavePath string `json:"dailyNoteSavePath"`+ DailyNoteTemplatePath string `json:"dailyNoteTemplatePath"`+ SortMode int `json:"sortMode"`+ Encrypted bool `json:"encrypted"`+ BoxCrypt *NotebookEncryption `json:"boxCrypt"`+}++type NotebookConfData struct {+ Box string `json:"box"`+ Name string `json:"name"`+ Conf *NotebookConf `json:"conf"`+}++type ImportNotebookCryptoBackupRequest struct {+ File *multipart.FileHeader `json:"file" api:"nonnullable"`+ Password string `json:"password" api:"optional"`+}++type NotebookInfo struct {+ ID string `json:"id"`+ Name string `json:"name"`+ DocCount int `json:"docCount"`+ Size uint64 `json:"size"`+ HSize string `json:"hSize"`+ Mtime int64 `json:"mtime"`+ CTime int64 `json:"ctime"`+ HMtime string `json:"hMtime"`+ HCtime string `json:"hCtime"`+}++type NotebookInfoData struct {+ BoxInfo *NotebookInfo `json:"boxInfo"`+}++type EncryptedNotebookStatus struct {+ ID string `json:"id"`+ Name string `json:"name"`+ Unlocked bool `json:"unlocked"`+ State string `json:"state" api:"enum=Locked|Unlocking|Unlocked|Locking|Error"`+}++type EncryptedNotebookStatusData struct {+ Enabled bool `json:"enabled"`+ State string `json:"state" api:"enum=Disabled|Enabled|RecoveryRequired"`+ Count int `json:"count"`+ Boxes []EncryptedNotebookStatus `json:"boxes" api:"nonnullable"`+ MigrationPending bool `json:"migrationPending"`+ MigrationBoxes []string `json:"migrationBoxes"`+ HasHistoryDependency bool `json:"hasHistoryDependency"`+}++type NotebookPasswordRequest struct {+ Password string `json:"password" api:"trim"`+}++type CreateEncryptedNotebookRequest struct {+ Name string `json:"name"`+ NotebookPasswordRequest+}++type UnlockNotebookRequest struct {+ NotebookIDRequest+ NotebookPasswordRequest+}++type ChangeMasterPasswordRequest struct {+ OldPassword string `json:"oldPassword" api:"trim"`+ NewPassword string `json:"newPassword" api:"trim"`+}++type NotebookCryptoAutoLockRequest struct {+ AutoLockMinutes float64 `json:"autoLockMinutes"`+}++type NotebookCryptoBackupData struct {+ File string `json:"file"`+}+type NotebookIDRequest struct {Notebook string `json:"notebook" api:"trim"`}diff --git a/kernel/apicontract/notebook_patch.go b/kernel/apicontract/notebook_patch.gonew file mode 100644index 0000000000..5553dbc3e1--- /dev/null+++ b/kernel/apicontract/notebook_patch.go@@ -0,0 +1,34 @@+package apicontract++// Base64Bytes 保留 JSON 字节切片的 Base64 字符串及数字数组输入。+type Base64Bytes []byte++type NotebookEncryptionPatch struct {+ Spec *int `json:"spec" api:"optional"`+ WrappedDEK Base64Bytes `json:"wrappedDEK" api:"optional,nullable"`+ WrapNonce Base64Bytes `json:"wrapNonce" api:"optional,nullable"`+ Metadata Base64Bytes `json:"metadata" api:"optional,nullable"`+ CreatedAt *int64 `json:"createdAt" api:"optional"`+}++type NotebookConfPatch struct {+ Name *string `json:"name" api:"optional"`+ Sort *int `json:"sort" api:"optional"`+ Icon *string `json:"icon" api:"optional"`+ Closed *bool `json:"closed" api:"optional"`+ RefCreateSaveBox *string `json:"refCreateSaveBox" api:"optional"`+ RefCreateSavePath *string `json:"refCreateSavePath" api:"optional"`+ DocCreateSaveBox *string `json:"docCreateSaveBox" api:"optional"`+ DocCreateSavePath *string `json:"docCreateSavePath" api:"optional"`+ DocCreateTemplatePath *string `json:"docCreateTemplatePath" api:"optional"`+ DailyNoteSavePath *string `json:"dailyNoteSavePath" api:"optional"`+ DailyNoteTemplatePath *string `json:"dailyNoteTemplatePath" api:"optional"`+ SortMode *int `json:"sortMode" api:"optional"`+ Encrypted *bool `json:"encrypted" api:"optional"`+ BoxCrypt *NotebookEncryptionPatch `json:"boxCrypt" api:"optional"`+}++type SetNotebookConfRequest struct {+ Notebook string `json:"notebook"`+ Conf *NotebookConfPatch `json:"conf" api:"optional,legacyobject"`+}diff --git a/kernel/apicontract/notebook_test.go b/kernel/apicontract/notebook_test.goindex f8d6ef3600..842e549ec4 100644--- a/kernel/apicontract/notebook_test.go+++ b/kernel/apicontract/notebook_test.go@@ -1,10 +1,60 @@package apicontractimport (+ "encoding/json""strings""testing")+func TestReorderNotebookCompatibility(t *testing.T) {+ request, err := ReorderNotebooks.Decode(strings.NewReader(`{"SOURCEIDS":[null,"id"],"TARGETID":"target","POSITION":"before"}`))+ if err != nil || len(request.SourceIDs) != 2 || request.SourceIDs[0] != "" || request.TargetID != "target" || request.Position != "before" {+ t.Fatalf("struct decoding compatibility changed: %+v, %v", request, err)+ }+ for _, body := range []string{`null`, `{}`, `{"sourceIDs":null,"targetID":null,"position":null}`} {+ if _, err := ReorderNotebooks.Decode(strings.NewReader(body)); err != nil {+ t.Fatalf("business validation must handle missing fields: %v", err)+ }+ }+ if _, err := ReorderNotebooks.Decode(strings.NewReader("")); err == nil || err.Error() != "Parses request [/api/notebook/reorder] failed: EOF" {+ t.Fatalf("empty request error changed: %v", err)+ }+ bundle, err := BuildBundle()+ if err != nil {+ t.Fatal(err)+ }+ response, err := json.Marshal(ReorderNotebooks.FailureWithData(-1, "failed", &ReorderData{}))+ if err != nil {+ t.Fatal(err)+ }+ if err := bundle.ValidateResponse("POST", "/api/notebook/reorder", response); err != nil {+ t.Fatal(err)+ }+}++func TestNotebookCryptoRequestCompatibility(t *testing.T) {+ request, err := UnlockNotebook.Decode(strings.NewReader(`{"notebook":" 20260101000000-abcdefg ","password":" secret "}`))+ if err != nil || request.Notebook != "20260101000000-abcdefg" || request.Password != "secret" {+ t.Fatalf("notebook and password trimming changed: %v", err)+ }+ for _, body := range []string{`{}`, `{"password":null}`, `{"password":" "}`, `{"password":123}`} {+ if _, err := EnableEncryptedNotebooks.Decode(strings.NewReader(body)); err == nil {+ t.Fatal("invalid password accepted")+ }+ }+ for _, body := range []string{`{"autoLockMinutes":1.9}`, `{"autoLockMinutes":-2}`, `{"autoLockMinutes":0}`} {+ if _, err := SetNotebookCryptoAutoLock.Decode(strings.NewReader(body)); err != nil {+ t.Fatalf("numeric minutes rejected: %v", err)+ }+ }+ if _, err := SetNotebookCryptoAutoLock.Decode(strings.NewReader(`{"autoLockMinutes":"1"}`)); err == nil {+ t.Fatal("string minutes accepted")+ }+ if _, err := TouchEncryptedNotebooks.Decode(strings.NewReader("not JSON")); err != nil {+ t.Fatalf("bodyless endpoint began parsing a request body: %v", err)+ }+}+func TestNotebookRequestCompatibility(t *testing.T) {request, err := RenameNotebook.Decode(strings.NewReader(`{"notebook":" 20260101000000-abcdefg ","name":" "}`))if err != nil || request.Notebook != "20260101000000-abcdefg" || request.Name != " " {diff --git a/kernel/apicontract/response.go b/kernel/apicontract/response.goindex 8c9ce96f8b..5d22cd6d72 100644--- a/kernel/apicontract/response.go+++ b/kernel/apicontract/response.go@@ -2,6 +2,14 @@ package apicontractimport "encoding/json"+// FailureWithData 仅为显式声明失败载荷的端点保留业务结果。+func (e Endpoint[Request, Data]) FailureWithData(code int, msg string, data Data) Response[Data] {+ if !e.definition.DataOnError {+ panic("endpoint does not declare data on error")+ }+ return Response[Data]{code: code, msg: msg, data: data}+}+// Null 表示成功但没有数据,线协议始终写出 null。type Null struct{}diff --git a/kernel/apicontract/schema.go b/kernel/apicontract/schema.goindex f39deb3e0f..dfd2d59467 100644--- a/kernel/apicontract/schema.go+++ b/kernel/apicontract/schema.go@@ -4,6 +4,7 @@ import ("encoding/json""fmt""math"+ "mime/multipart""reflect""sort""strings"@@ -13,6 +14,7 @@ import (type Schema struct {Ref string `json:"$ref,omitempty"`Type string `json:"type,omitempty"`+ Format string `json:"format,omitempty"`Enum []any `json:"enum,omitempty"`AnyOf []*Schema `json:"anyOf,omitempty"`Properties map[string]*Schema `json:"properties,omitempty"`@@ -70,6 +72,36 @@ func nonnullable(schema *Schema) *Schema {}func (b *schemaBuilder) schema(t reflect.Type, input bool) (*Schema, error) {+ if t == reflect.TypeFor[BlockOperationData]() {+ options, err := b.schema(reflect.TypeFor[BlockDeleteData](), input)+ if err != nil {+ return nil, err+ }+ return &Schema{AnyOf: []*Schema{{Type: "null"}, {Type: "string"}, options}}, nil+ }+ if t == reflect.TypeFor[BlockOperationResult]() {+ return &Schema{AnyOf: []*Schema{{Type: "null"}, {Type: "string"}, {Type: "array", Items: &Schema{Type: "string"}}}}, nil+ }+ if t == reflect.TypeFor[JSONValue]() {+ ref := &Schema{Ref: "#/$defs/JSONValue"}+ b.definitions["JSONValue"] = &Schema{AnyOf: []*Schema{+ {Type: "null"}, {Type: "boolean"}, {Type: "number"}, {Type: "string"},+ {Type: "array", Items: ref}, {Type: "object", AdditionalProperties: ref},+ }}+ return ref, nil+ }+ if t == reflect.TypeFor[Base64Bytes]() {+ if input {+ return nullable(&Schema{AnyOf: []*Schema{{Type: "string"}, {Type: "array", Items: &Schema{Type: "integer"}}}}), nil+ }+ return nullable(&Schema{Type: "string"}), nil+ }+ if t == reflect.TypeFor[*multipart.FileHeader]() {+ if !input {+ return nil, fmt.Errorf("uploaded files are request-only")+ }+ return &Schema{Type: "string", Format: "binary"}, nil+ }if t == reflect.TypeFor[Null]() {return &Schema{Type: "null"}, nil}@@ -195,6 +227,10 @@ func (b *schemaBuilder) fields(object *Schema, t reflect.Type, input bool) errorfor _, option := range strings.Split(field.Tag.Get("api"), ",") {switch {case option == "", option == "optional", option == "nullable", option == "nonnullable":+ case option == "legacyobject":+ if field.Type.Kind() != reflect.Pointer || field.Type.Elem().Kind() != reflect.Struct {+ return fmt.Errorf("legacyobject requires a struct pointer: %s.%s", t, name)+ }case option == "trim", option == "ignoretype", strings.HasPrefix(option, "enum="):if field.Type.Kind() != reflect.String {return fmt.Errorf("API option %s requires a string: %s.%s", option, t, name)@@ -218,7 +254,15 @@ func (b *schemaBuilder) fields(object *Schema, t reflect.Type, input bool) error}} else if len(tag) > 1 && tag[1] == "omitempty" {optional = true- child = nonnullable(child)+ if field.Type.Kind() == reflect.Pointer {+ // 仅外层空指针被省略,内层指针或集合仍可序列化为 null。+ child, err = b.schema(field.Type.Elem(), false)+ if err != nil {+ return err+ }+ } else {+ child = nonnullable(child)+ }}if has("nonnullable") {child = nonnullable(child)@@ -257,6 +301,11 @@ func BuildBundle() (*Bundle, error) {if definition.Request.Kind() != reflect.Struct {return nil, fmt.Errorf("request contract must be a struct: %s", definition.Name)}+ if definition.Body == MultipartBody {+ if err := validateMultipartRequest(definition.Request); err != nil {+ return nil, err+ }+ }request, err := b.schema(definition.Request, true)if err != nil {return nil, err@@ -278,6 +327,9 @@ func BuildBundle() (*Bundle, error) {if definition.ErrorText {errorData.AnyOf = append(errorData.AnyOf, &Schema{Type: "string"})}+ if definition.DataOnError {+ errorData.AnyOf = append(errorData.AnyOf, data)+ }failure := object(map[string]*Schema{"code": {Type: "integer", Enum: codes}, "msg": {Type: "string"}, "data": errorData}, "code", "msg", "data")// 中间件可能使用带命令元数据的统一信封,保留这些额外的顶层字段。failure.AdditionalProperties = truediff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.jsonindex b27f0d209a..0aadbf8a2c 100644--- a/kernel/apicontract/schema.json+++ b/kernel/apicontract/schema.json@@ -1,6 +1,26 @@{"$schema": "https://json-schema.org/draft/2020-12/schema","$defs": {+ "AppendBlockRequestInput": {+ "type": "object",+ "properties": {+ "data": {+ "type": "string"+ },+ "dataType": {+ "type": "string"+ },+ "parentID": {+ "type": "string"+ }+ },+ "required": [+ "data",+ "dataType",+ "parentID"+ ],+ "additionalProperties": false+ },"AppendHeadingChildrenRequestInput": {"type": "object","properties": {@@ -29,77 +49,130 @@],"additionalProperties": false},- "BatchSetBlockAttrsRequestInput": {+ "BatchInsertBlockRequestInput": {"type": "object","properties": {- "blockAttrs": {+ "blocks": {"type": "array","items": {- "$ref": "#/$defs/SetBlockAttrsRequestInput"+ "$ref": "#/$defs/BlockInsertInputInput"}}},"required": [- "blockAttrs"+ "blocks"],"additionalProperties": false},- "BlockFoldData": {+ "BatchParentBlockRequestInput": {"type": "object","properties": {- "isFolded": {- "type": "boolean"- },- "isRoot": {- "type": "boolean"+ "blocks": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/PrependBlockRequestInput"+ }}},"required": [- "isFolded",- "isRoot"+ "blocks"],"additionalProperties": false},- "BlockIDRequestInput": {+ "BatchSetBlockAttrsRequestInput": {"type": "object","properties": {- "id": {- "type": "string"+ "blockAttrs": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/SetBlockAttrsRequestInput"+ }}},"required": [- "id"+ "blockAttrs"],"additionalProperties": false},- "BlockIDsRequestInput": {+ "BatchTaskListMarkerRequestInput": {"type": "object","properties": {- "ids": {+ "items": {"type": "array","items": {- "type": "string"+ "$ref": "#/$defs/TaskListMarkerRequestInput"}}},"required": [- "ids"+ "items"],"additionalProperties": false},- "BlockInfoData": {- "anyOf": [- {- "$ref": "#/$defs/FullBlockInfo"+ "BatchUpdateBlockRequestInput": {+ "type": "object",+ "properties": {+ "blocks": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/UpdateBlockRequestInput"+ }+ }+ },+ "required": [+ "blocks"+ ],+ "additionalProperties": false+ },+ "BlockBreadcrumbChildren": {+ "type": "object",+ "properties": {+ "hasMore": {+ "type": "boolean"},- {- "$ref": "#/$defs/PublishedBlockInfo"+ "items": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockPath"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]}- ]+ },+ "required": [+ "hasMore",+ "items"+ ],+ "additionalProperties": false},- "BlockInfoRequestInput": {+ "BlockBreadcrumbChildrenRequestInput": {"type": "object","properties": {+ "excludeTypes": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },"id": {"type": "string"},@@ -116,6 +189,16 @@}]},+ "limit": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ },"notebook": {"anyOf": [{@@ -125,6 +208,16 @@"type": "null"}]+ },+ "offset": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]}},"required": [@@ -132,9 +225,22 @@],"additionalProperties": false},- "BlockQueryRequestInput": {+ "BlockBreadcrumbRequestInput": {"type": "object","properties": {+ "excludeTypes": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },"id": {"type": "string"},@@ -167,101 +273,66 @@],"additionalProperties": false},- "BlockRelevantData": {+ "BlockDOMData": {"type": "object","properties": {- "nextID": {- "type": "string"- },- "parentID": {+ "dom": {"type": "string"},- "previousID": {+ "id": {"type": "string"}},"required": [- "nextID",- "parentID",- "previousID"+ "dom",+ "id"],"additionalProperties": false},- "BlockSiblingData": {+ "BlockDeleteData": {"type": "object","properties": {- "next": {- "type": "string"- },- "parent": {- "type": "string"- },- "previous": {- "type": "string"+ "createEmptyParagraph": {+ "type": "boolean"}},"required": [- "next",- "parent",- "previous"+ "createEmptyParagraph"],"additionalProperties": false},- "BlocksQueryRequestInput": {+ "BlockFoldData": {"type": "object","properties": {- "id": {- "anyOf": [- {- "type": "string"- },- {- "type": "null"- }- ]- },- "ids": {- "type": "array",- "items": {- "type": "string"- }+ "isFolded": {+ "type": "boolean"},- "notebook": {- "anyOf": [- {- "type": "string"- },- {- "type": "null"- }- ]+ "isRoot": {+ "type": "boolean"}},"required": [- "ids"+ "isFolded",+ "isRoot"],"additionalProperties": false},- "BootProgressData": {+ "BlockIDRequestInput": {"type": "object","properties": {- "details": {+ "id": {"type": "string"- },- "progress": {- "type": "integer"}},"required": [- "details",- "progress"+ "id"],"additionalProperties": false},- "ChangeSortNotebookRequestInput": {+ "BlockIDsRequestInput": {"type": "object","properties": {- "notebooks": {+ "ids": {"type": "array","items": {"type": "string"@@ -269,41 +340,43 @@}},"required": [- "notebooks"+ "ids"],"additionalProperties": false},- "CheckSnapshotData": {- "type": "object",- "properties": {- "changed": {- "type": "boolean"+ "BlockInfoData": {+ "anyOf": [+ {+ "$ref": "#/$defs/FullBlockInfo"+ },+ {+ "$ref": "#/$defs/PublishedBlockInfo"}- },- "required": [- "changed"- ],- "additionalProperties": false+ ]},- "CloseNotebookRequestInput": {+ "BlockInfoRequestInput": {"type": "object","properties": {- "notebook": {+ "id": {"type": "string"- }- },- "required": [- "notebook"- ],- "additionalProperties": false- },- "CreateNotebookData": {- "type": "object",- "properties": {+ },+ "ids": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },"notebook": {"anyOf": [{- "$ref": "#/$defs/Notebook"+ "type": "string"},{"type": "null"@@ -312,139 +385,20 @@}},"required": [- "notebook"+ "id"],"additionalProperties": false},- "CreateNotebookRequestInput": {+ "BlockInsertInputInput": {"type": "object","properties": {- "name": {- "type": "string"- }- },- "required": [- "name"- ],- "additionalProperties": false- },- "CreateSnapshotData": {- "type": "object",- "properties": {- "created": {- "type": "boolean"- },- "id": {- "type": "string"- }- },- "required": [- "created",- "id"- ],- "additionalProperties": false- },- "CreateSnapshotRequestInput": {- "type": "object",- "properties": {- "memo": {- "type": "string"- }- },- "additionalProperties": false- },- "DOMTextRequestInput": {- "type": "object",- "properties": {- "dom": {- "type": "string"- }- },- "required": [- "dom"- ],- "additionalProperties": false- },- "DocOrdersRequestInput": {- "type": "object",- "properties": {- "id": {- "type": "string"- }- },- "required": [- "id"- ],- "additionalProperties": false- },- "DownloadInstallPkgRequestInput": {- "type": "object",- "properties": {- "downloadInstallPkg": {- "type": "boolean"- }- },- "required": [- "downloadInstallPkg"- ],- "additionalProperties": false- },- "EditorReadOnlyRequestInput": {- "type": "object",- "properties": {- "readonly": {- "type": "boolean"- }- },- "required": [- "readonly"- ],- "additionalProperties": false- },- "EmptyRequestInput": {- "type": "object",- "additionalProperties": false- },- "FullBlockInfo": {- "type": "object",- "properties": {- "box": {- "type": "string"- },- "path": {- "type": "string"- },- "rootChildID": {+ "data": {"type": "string"},- "rootID": {- "type": "string"- },- "rootIcon": {+ "dataType": {"type": "string"},- "rootTitle": {- "type": "string"- },- "rootTitleEmpty": {- "type": "boolean"- }- },- "required": [- "box",- "path",- "rootChildID",- "rootID",- "rootIcon",- "rootTitle",- "rootTitleEmpty"- ],- "additionalProperties": false- },- "GetTagRequestInput": {- "type": "object",- "properties": {- "app": {+ "nextID": {"anyOf": [{"type": "string"@@ -454,20 +408,20 @@}]},- "ignoreMaxListHint": {+ "parentID": {"anyOf": [{- "type": "boolean"+ "type": "string"},{"type": "null"}]},- "sort": {+ "previousID": {"anyOf": [{- "type": "number"+ "type": "string"},{"type": "null"@@ -475,98 +429,61 @@]}},+ "required": [+ "data",+ "dataType"+ ],"additionalProperties": false},- "HeadingChildrenRequestInput": {+ "BlockKramdownData": {"type": "object","properties": {"id": {"type": "string"},- "removeFoldAttr": {- "anyOf": [- {- "type": "boolean"- },- {- "type": "null"- }- ]+ "kramdown": {+ "type": "string"}},"required": [- "id"+ "id",+ "kramdown"],"additionalProperties": false},- "ListNotebooksData": {+ "BlockKramdownRequestInput": {"type": "object","properties": {- "boxDocEnabled": {- "type": "boolean"+ "id": {+ "type": "string"},- "notebooks": {+ "ids": {"anyOf": [{"type": "array","items": {- "anyOf": [- {- "$ref": "#/$defs/Notebook"- },- {- "type": "null"- }- ]+ "type": "string"}},{"type": "null"}]- }- },- "required": [- "boxDocEnabled",- "notebooks"- ],- "additionalProperties": false- },- "ListNotebooksRequestInput": {- "type": "object",- "properties": {- "flashcard": {+ },+ "mode": {"anyOf": [{- "type": "boolean"+ "type": "string"},{"type": "null"}]- }- },- "additionalProperties": false- },- "LockScreenRequestInput": {- "type": "object",- "properties": {- "lockScreenMode": {- "type": "number"- }- },- "required": [- "lockScreenMode"- ],- "additionalProperties": false- },- "NetworkData": {- "type": "object",- "properties": {- "proxy": {+ },+ "notebook": {"anyOf": [{- "$ref": "#/$defs/NetworkProxy"+ "type": "string"},{"type": "null"@@ -575,167 +492,232 @@}},"required": [- "proxy"+ "id"],"additionalProperties": false},- "NetworkProxy": {+ "BlockOperation": {"type": "object","properties": {- "host": {- "type": "string"+ "action": {+ "type": "string",+ "enum": [+ "delete",+ "insert",+ "update",+ "foldHeading",+ "unfoldHeading",+ "setAttrs",+ "moveOutlineHeading",+ "appendInsert",+ "prependInsert"+ ]},- "port": {+ "avID": {"type": "string"},- "scheme": {- "type": "string"- }- },- "required": [- "host",- "port",- "scheme"- ],- "additionalProperties": false- },- "NetworkProxyInput": {- "type": "object",- "properties": {- "host": {+ "backRelationKeyID": {"type": "string"},- "port": {+ "blockID": {"type": "string"},- "scheme": {- "type": "string"- }- },- "required": [- "host",- "port",- "scheme"- ],- "additionalProperties": false- },- "NetworkServeRequestInput": {- "type": "object",- "properties": {- "networkServe": {- "type": "boolean"- }- },- "required": [- "networkServe"- ],- "additionalProperties": false- },- "NetworkServeTLSRequestInput": {- "type": "object",- "properties": {- "networkServeTLS": {- "type": "boolean"- }- },- "required": [- "networkServeTLS"- ],- "additionalProperties": false- },- "Notebook": {- "type": "object",- "properties": {- "closed": {- "type": "boolean"+ "blockIDs": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]},- "dueFlashcardCount": {- "type": "integer"+ "context": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]},- "encrypted": {- "type": "boolean"+ "data": {+ "anyOf": [+ {+ "type": "null"+ },+ {+ "type": "string"+ },+ {+ "$ref": "#/$defs/BlockDeleteData"+ }+ ]},- "flashcardCount": {- "type": "integer"+ "deckID": {+ "type": "string"},- "icon": {+ "format": {+ "type": "string"+ },+ "groupID": {"type": "string"},"id": {"type": "string"},+ "ignoreDefaultFill": {+ "type": "boolean"+ },+ "isDetached": {+ "type": "boolean"+ },+ "isTwoWay": {+ "type": "boolean"+ },+ "keyID": {+ "type": "string"+ },+ "layout": {+ "type": "string"+ },"name": {"type": "string"},- "newFlashcardCount": {- "type": "integer"+ "nextID": {+ "type": "string"},- "sort": {- "type": "integer"+ "parentID": {+ "type": "string"},- "sortMode": {- "type": "integer"+ "previousID": {+ "type": "string"},- "state": {+ "removeDest": {+ "type": "boolean"+ },+ "retData": {+ "anyOf": [+ {+ "type": "null"+ },+ {+ "type": "string"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ ]+ },+ "rootID": {+ "type": "string"+ },+ "rowID": {+ "type": "string"+ },+ "srcIDs": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "srcs": {+ "type": "null"+ },+ "targetGroupID": {+ "type": "string"+ },+ "type": {"type": "string","enum": [- "Locked",- "Unlocking",- "Unlocked",- "Locking",- "Error"+ ""]},- "subFileCount": {- "type": "integer"+ "viewID": {+ "type": "string"},- "unlocked": {- "type": "boolean"+ "viewIDs": {+ "type": "array",+ "items": {+ "type": "string"+ }}},"required": [- "closed",- "dueFlashcardCount",- "encrypted",- "flashcardCount",- "icon",+ "action",+ "avID",+ "backRelationKeyID",+ "blockID",+ "blockIDs",+ "context",+ "data",+ "deckID",+ "format",+ "groupID","id",+ "ignoreDefaultFill",+ "isDetached",+ "isTwoWay",+ "keyID",+ "layout","name",- "newFlashcardCount",- "sort",- "sortMode",- "subFileCount",- "unlocked"- ],- "additionalProperties": false- },- "NotebookIDRequestInput": {- "type": "object",- "properties": {- "notebook": {- "type": "string"- }- },- "required": [- "notebook"+ "nextID",+ "parentID",+ "previousID",+ "removeDest",+ "retData",+ "rootID",+ "rowID",+ "srcIDs",+ "srcs",+ "targetGroupID",+ "type",+ "viewID"],"additionalProperties": false},- "PinnedDoc": {+ "BlockPath": {"type": "object","properties": {- "childrenSortMode": {+ "children": {"anyOf": [{- "type": "integer"+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockPath"+ },+ {+ "type": "null"+ }+ ]+ }},{"type": "null"}]},- "icon": {- "type": "string"+ "hasChildren": {+ "type": "boolean"},"id": {"type": "string"@@ -743,143 +725,161 @@"name": {"type": "string"},- "notebook": {+ "subType": {"type": "string"},- "path": {+ "type": {"type": "string"- },- "subFileCount": {- "type": "integer"- },- "unavailable": {- "type": "boolean"}},"required": [- "childrenSortMode",- "icon",+ "children","id","name",- "notebook",- "path",- "subFileCount",- "unavailable"+ "subType",+ "type"],"additionalProperties": false},- "PublishedBlockInfo": {+ "BlockQueryRequestInput": {"type": "object","properties": {- "publishAccessRequired": {- "type": "boolean",- "enum": [- true- ]- },- "rootID": {- "type": "string"- },- "rootIcon": {+ "id": {"type": "string"},- "rootTitle": {- "type": "string"+ "ids": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]},- "rootTitleEmpty": {- "type": "boolean"+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]}},"required": [- "publishAccessRequired",- "rootID",- "rootIcon",- "rootTitle",- "rootTitleEmpty"+ "id"],"additionalProperties": false},- "RemoveBookmarkRequestInput": {+ "BlockRelevantData": {"type": "object","properties": {- "bookmark": {+ "nextID": {+ "type": "string"+ },+ "parentID": {+ "type": "string"+ },+ "previousID": {"type": "string"}},"required": [- "bookmark"+ "nextID",+ "parentID",+ "previousID"],"additionalProperties": false},- "RemoveTagRequestInput": {+ "BlockReminderRequestInput": {"type": "object","properties": {- "label": {+ "id": {+ "type": "string"+ },+ "timed": {"type": "string"}},"required": [- "label"+ "id",+ "timed"],"additionalProperties": false},- "RenameBookmarkRequestInput": {+ "BlockSiblingData": {"type": "object","properties": {- "newBookmark": {+ "next": {"type": "string"},- "oldBookmark": {- "type": "string"- }- },- "required": [- "newBookmark",- "oldBookmark"- ],- "additionalProperties": false- },- "RenameNotebookRequestInput": {- "type": "object",- "properties": {- "name": {+ "parent": {"type": "string"},- "notebook": {+ "previous": {"type": "string"}},"required": [- "name",- "notebook"+ "next",+ "parent",+ "previous"],"additionalProperties": false},- "RenameTagRequestInput": {+ "BlockStat": {"type": "object","properties": {- "newLabel": {- "type": "string"+ "blockCount": {+ "type": "integer"},- "oldLabel": {- "type": "string"+ "imageCount": {+ "type": "integer"+ },+ "linkCount": {+ "type": "integer"+ },+ "refCount": {+ "type": "integer"+ },+ "runeCount": {+ "type": "integer"+ },+ "wordCount": {+ "type": "integer"}},"required": [- "newLabel",- "oldLabel"+ "blockCount",+ "imageCount",+ "linkCount",+ "refCount",+ "runeCount",+ "wordCount"],"additionalProperties": false},- "SearchHistoryData": {+ "BlockTransaction": {"type": "object","properties": {- "histories": {+ "doOperations": {"anyOf": [{"type": "array","items": {- "type": "string"+ "anyOf": [+ {+ "$ref": "#/$defs/BlockOperation"+ },+ {+ "type": "null"+ }+ ]}},{@@ -887,24 +887,84 @@}]},- "pageCount": {- "type": "integer"+ "templateDocTreePlanID": {+ "type": "string"},- "totalCount": {+ "timestamp": {"type": "integer"+ },+ "undoOperations": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockOperation"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]}},"required": [- "histories",- "pageCount",- "totalCount"+ "doOperations",+ "timestamp",+ "undoOperations"],"additionalProperties": false},- "SearchHistoryRequestInput": {+ "BlockTreeInfo": {"type": "object","properties": {- "notebook": {+ "id": {+ "type": "string"+ },+ "nextID": {+ "type": "string"+ },+ "nextType": {+ "type": "string"+ },+ "parentID": {+ "type": "string"+ },+ "parentType": {+ "type": "string"+ },+ "previousID": {+ "type": "string"+ },+ "previousType": {+ "type": "string"+ },+ "type": {+ "type": "string"+ }+ },+ "required": [+ "id",+ "nextID",+ "nextType",+ "parentID",+ "parentType",+ "previousID",+ "previousType",+ "type"+ ],+ "additionalProperties": false+ },+ "BlocksKramdownRequestInput": {+ "type": "object",+ "properties": {+ "id": {"anyOf": [{"type": "string"@@ -914,7 +974,13 @@}]},- "op": {+ "ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "mode": {"anyOf": [{"type": "string"@@ -924,17 +990,26 @@}]},- "page": {+ "notebook": {"anyOf": [{- "type": "number"+ "type": "string"},{"type": "null"}]- },- "query": {+ }+ },+ "required": [+ "ids"+ ],+ "additionalProperties": false+ },+ "BlocksQueryRequestInput": {+ "type": "object",+ "properties": {+ "id": {"anyOf": [{"type": "string"@@ -944,10 +1019,16 @@}]},- "type": {+ "ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "notebook": {"anyOf": [{- "type": "number"+ "type": "string"},{"type": "null"@@ -955,235 +1036,7655 @@]}},+ "required": [+ "ids"+ ],"additionalProperties": false},- "SearchTagData": {+ "BlocksWordCountRequestInput": {"type": "object","properties": {- "k": {- "type": "string"+ "id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]},- "tags": {+ "ids": {"type": "array","items": {"type": "string"}+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "reqId": {+ "anyOf": [+ {+ "$ref": "#/$defs/JSONValue"+ },+ {+ "type": "null"+ }+ ]}},"required": [- "k",- "tags"+ "ids"],"additionalProperties": false},- "SearchTagRequestInput": {+ "BootProgressData": {"type": "object","properties": {- "k": {+ "details": {"type": "string"+ },+ "progress": {+ "type": "integer"}},"required": [- "k"+ "details",+ "progress"],"additionalProperties": false},- "SetBlockAttrsRequestInput": {+ "ChangeMasterPasswordRequestInput": {"type": "object","properties": {- "attrs": {- "type": "object",- "additionalProperties": {- "anyOf": [- {- "type": "string"- },- {- "type": "null"- }- ]- }+ "newPassword": {+ "type": "string"},- "id": {+ "oldPassword": {"type": "string"}},"required": [- "attrs",- "id"+ "newPassword",+ "oldPassword"],"additionalProperties": false},- "SetNotebookIconRequestInput": {+ "ChangeSortNotebookRequestInput": {"type": "object","properties": {- "icon": {- "type": "string"- },- "notebook": {- "type": "string"+ "notebooks": {+ "type": "array",+ "items": {+ "type": "string"+ }}},"required": [- "icon",- "notebook"+ "notebooks"],"additionalProperties": false},- "SetSnapshotMemoRequestInput": {+ "CheckBlocksExistRequestInput": {"type": "object","properties": {"id": {- "type": "string"+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]},- "memo": {- "type": "string"+ "ids": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/JSONValue"+ }+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]}},"required": [- "id",- "memo"+ "ids"],"additionalProperties": false},- "TagData": {+ "CheckSnapshotData": {"type": "object","properties": {- "children": {- "anyOf": [- {+ "changed": {+ "type": "boolean"+ }+ },+ "required": [+ "changed"+ ],+ "additionalProperties": false+ },+ "ChildBlock": {+ "type": "object",+ "properties": {+ "content": {+ "type": "string"+ },+ "id": {+ "type": "string"+ },+ "markdown": {+ "type": "string"+ },+ "subType": {+ "type": "string"+ },+ "type": {+ "type": "string"+ }+ },+ "required": [+ "id",+ "type"+ ],+ "additionalProperties": false+ },+ "CloseNotebookRequestInput": {+ "type": "object",+ "properties": {+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "notebook"+ ],+ "additionalProperties": false+ },+ "ContentWordCountRequestInput": {+ "type": "object",+ "properties": {+ "content": {+ "type": "string"+ },+ "reqId": {+ "anyOf": [+ {+ "$ref": "#/$defs/JSONValue"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "content"+ ],+ "additionalProperties": false+ },+ "CreateEncryptedNotebookRequestInput": {+ "type": "object",+ "properties": {+ "name": {+ "type": "string"+ },+ "password": {+ "type": "string"+ }+ },+ "required": [+ "name",+ "password"+ ],+ "additionalProperties": false+ },+ "CreateNotebookData": {+ "type": "object",+ "properties": {+ "notebook": {+ "anyOf": [+ {+ "$ref": "#/$defs/Notebook"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "notebook"+ ],+ "additionalProperties": false+ },+ "CreateNotebookRequestInput": {+ "type": "object",+ "properties": {+ "name": {+ "type": "string"+ }+ },+ "required": [+ "name"+ ],+ "additionalProperties": false+ },+ "CreateSnapshotData": {+ "type": "object",+ "properties": {+ "created": {+ "type": "boolean"+ },+ "id": {+ "type": "string"+ }+ },+ "required": [+ "created",+ "id"+ ],+ "additionalProperties": false+ },+ "CreateSnapshotRequestInput": {+ "type": "object",+ "properties": {+ "memo": {+ "type": "string"+ }+ },+ "additionalProperties": false+ },+ "DOMTextRequestInput": {+ "type": "object",+ "properties": {+ "dom": {+ "type": "string"+ }+ },+ "required": [+ "dom"+ ],+ "additionalProperties": false+ },+ "DailyNoteBlockRequestInput": {+ "type": "object",+ "properties": {+ "data": {+ "type": "string"+ },+ "dataType": {+ "type": "string"+ },+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "data",+ "dataType",+ "notebook"+ ],+ "additionalProperties": false+ },+ "DeleteBlockRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "DocAttrView": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ }+ },+ "required": [+ "id",+ "name"+ ],+ "additionalProperties": false+ },+ "DocInfo": {+ "type": "object",+ "properties": {+ "attrViews": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/DocAttrView"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "ial": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "icon": {+ "type": "string"+ },+ "id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "refCount": {+ "type": "integer"+ },+ "refIDs": {+ "anyOf": [+ {"type": "array","items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "rootID": {+ "type": "string"+ },+ "subFileCount": {+ "type": "integer"+ }+ },+ "required": [+ "attrViews",+ "ial",+ "icon",+ "id",+ "name",+ "refCount",+ "refIDs",+ "rootID",+ "subFileCount"+ ],+ "additionalProperties": false+ },+ "DocOrdersRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "DocsInfoRequestInput": {+ "type": "object",+ "properties": {+ "av": {+ "type": "boolean"+ },+ "ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "refCount": {+ "type": "boolean"+ }+ },+ "required": [+ "av",+ "ids",+ "refCount"+ ],+ "additionalProperties": false+ },+ "DownloadInstallPkgRequestInput": {+ "type": "object",+ "properties": {+ "downloadInstallPkg": {+ "type": "boolean"+ }+ },+ "required": [+ "downloadInstallPkg"+ ],+ "additionalProperties": false+ },+ "EditorReadOnlyRequestInput": {+ "type": "object",+ "properties": {+ "readonly": {+ "type": "boolean"+ }+ },+ "required": [+ "readonly"+ ],+ "additionalProperties": false+ },+ "EmbedStat": {+ "type": "object",+ "properties": {+ "complete": {+ "type": "boolean"+ },+ "cycleCount": {+ "type": "integer"+ },+ "depthLimitCount": {+ "type": "integer"+ },+ "failedQueryCount": {+ "type": "integer"+ },+ "failedResultCount": {+ "type": "integer"+ },+ "jsEmbedCount": {+ "type": "integer"+ },+ "queryEmbedCount": {+ "type": "integer"+ },+ "resultCount": {+ "type": "integer"+ },+ "truncatedQueryCount": {+ "type": "integer"+ }+ },+ "required": [+ "complete",+ "cycleCount",+ "depthLimitCount",+ "failedQueryCount",+ "failedResultCount",+ "jsEmbedCount",+ "queryEmbedCount",+ "resultCount",+ "truncatedQueryCount"+ ],+ "additionalProperties": false+ },+ "EmptyRequestInput": {+ "type": "object",+ "additionalProperties": false+ },+ "EncryptedNotebookStatus": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "state": {+ "type": "string",+ "enum": [+ "Locked",+ "Unlocking",+ "Unlocked",+ "Locking",+ "Error"+ ]+ },+ "unlocked": {+ "type": "boolean"+ }+ },+ "required": [+ "id",+ "name",+ "state",+ "unlocked"+ ],+ "additionalProperties": false+ },+ "EncryptedNotebookStatusData": {+ "type": "object",+ "properties": {+ "boxes": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/EncryptedNotebookStatus"+ }+ },+ "count": {+ "type": "integer"+ },+ "enabled": {+ "type": "boolean"+ },+ "hasHistoryDependency": {+ "type": "boolean"+ },+ "migrationBoxes": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "migrationPending": {+ "type": "boolean"+ },+ "state": {+ "type": "string",+ "enum": [+ "Disabled",+ "Enabled",+ "RecoveryRequired"+ ]+ }+ },+ "required": [+ "boxes",+ "count",+ "enabled",+ "hasHistoryDependency",+ "migrationBoxes",+ "migrationPending",+ "state"+ ],+ "additionalProperties": false+ },+ "FileAnnotationRefRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "FullBlockInfo": {+ "type": "object",+ "properties": {+ "box": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "rootChildID": {+ "type": "string"+ },+ "rootID": {+ "type": "string"+ },+ "rootIcon": {+ "type": "string"+ },+ "rootTitle": {+ "type": "string"+ },+ "rootTitleEmpty": {+ "type": "boolean"+ }+ },+ "required": [+ "box",+ "path",+ "rootChildID",+ "rootID",+ "rootIcon",+ "rootTitle",+ "rootTitleEmpty"+ ],+ "additionalProperties": false+ },+ "GetTagRequestInput": {+ "type": "object",+ "properties": {+ "app": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "ignoreMaxListHint": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "sort": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "HeadingChildrenRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "removeFoldAttr": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "HeadingFoldRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "scope": {+ "type": "string"+ }+ },+ "required": [+ "id",+ "scope"+ ],+ "additionalProperties": false+ },+ "ImportNotebookCryptoBackupRequestInput": {+ "type": "object",+ "properties": {+ "file": {+ "type": "string",+ "format": "binary"+ },+ "password": {+ "type": "string"+ }+ },+ "required": [+ "file"+ ],+ "additionalProperties": false+ },+ "InsertBlockRequestInput": {+ "type": "object",+ "properties": {+ "data": {+ "type": "string"+ },+ "dataType": {+ "type": "string"+ },+ "nextID": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "parentID": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "previousID": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "data",+ "dataType"+ ],+ "additionalProperties": false+ },+ "JSONValue": {+ "anyOf": [+ {+ "type": "null"+ },+ {+ "type": "boolean"+ },+ {+ "type": "number"+ },+ {+ "type": "string"+ },+ {+ "type": "array",+ "items": {+ "$ref": "#/$defs/JSONValue"+ }+ },+ {+ "type": "object",+ "additionalProperties": {+ "$ref": "#/$defs/JSONValue"+ }+ }+ ]+ },+ "ListNotebooksData": {+ "type": "object",+ "properties": {+ "boxDocEnabled": {+ "type": "boolean"+ },+ "notebooks": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/Notebook"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "boxDocEnabled",+ "notebooks"+ ],+ "additionalProperties": false+ },+ "ListNotebooksRequestInput": {+ "type": "object",+ "properties": {+ "flashcard": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "LockScreenRequestInput": {+ "type": "object",+ "properties": {+ "lockScreenMode": {+ "type": "number"+ }+ },+ "required": [+ "lockScreenMode"+ ],+ "additionalProperties": false+ },+ "MoveBlockRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "parentID": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "previousID": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "NetworkData": {+ "type": "object",+ "properties": {+ "proxy": {+ "anyOf": [+ {+ "$ref": "#/$defs/NetworkProxy"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "proxy"+ ],+ "additionalProperties": false+ },+ "NetworkProxy": {+ "type": "object",+ "properties": {+ "host": {+ "type": "string"+ },+ "port": {+ "type": "string"+ },+ "scheme": {+ "type": "string"+ }+ },+ "required": [+ "host",+ "port",+ "scheme"+ ],+ "additionalProperties": false+ },+ "NetworkProxyInput": {+ "type": "object",+ "properties": {+ "host": {+ "type": "string"+ },+ "port": {+ "type": "string"+ },+ "scheme": {+ "type": "string"+ }+ },+ "required": [+ "host",+ "port",+ "scheme"+ ],+ "additionalProperties": false+ },+ "NetworkServeRequestInput": {+ "type": "object",+ "properties": {+ "networkServe": {+ "type": "boolean"+ }+ },+ "required": [+ "networkServe"+ ],+ "additionalProperties": false+ },+ "NetworkServeTLSRequestInput": {+ "type": "object",+ "properties": {+ "networkServeTLS": {+ "type": "boolean"+ }+ },+ "required": [+ "networkServeTLS"+ ],+ "additionalProperties": false+ },+ "Notebook": {+ "type": "object",+ "properties": {+ "closed": {+ "type": "boolean"+ },+ "dueFlashcardCount": {+ "type": "integer"+ },+ "encrypted": {+ "type": "boolean"+ },+ "flashcardCount": {+ "type": "integer"+ },+ "icon": {+ "type": "string"+ },+ "id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "newFlashcardCount": {+ "type": "integer"+ },+ "sort": {+ "type": "integer"+ },+ "sortMode": {+ "type": "integer"+ },+ "state": {+ "type": "string",+ "enum": [+ "Locked",+ "Unlocking",+ "Unlocked",+ "Locking",+ "Error"+ ]+ },+ "subFileCount": {+ "type": "integer"+ },+ "unlocked": {+ "type": "boolean"+ }+ },+ "required": [+ "closed",+ "dueFlashcardCount",+ "encrypted",+ "flashcardCount",+ "icon",+ "id",+ "name",+ "newFlashcardCount",+ "sort",+ "sortMode",+ "subFileCount",+ "unlocked"+ ],+ "additionalProperties": false+ },+ "NotebookConf": {+ "type": "object",+ "properties": {+ "boxCrypt": {+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookEncryption"+ },+ {+ "type": "null"+ }+ ]+ },+ "closed": {+ "type": "boolean"+ },+ "dailyNoteSavePath": {+ "type": "string"+ },+ "dailyNoteTemplatePath": {+ "type": "string"+ },+ "docCreateSaveBox": {+ "type": "string"+ },+ "docCreateSavePath": {+ "type": "string"+ },+ "docCreateTemplatePath": {+ "type": "string"+ },+ "encrypted": {+ "type": "boolean"+ },+ "icon": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "refCreateSaveBox": {+ "type": "string"+ },+ "refCreateSavePath": {+ "type": "string"+ },+ "sort": {+ "type": "integer"+ },+ "sortMode": {+ "type": "integer"+ }+ },+ "required": [+ "boxCrypt",+ "closed",+ "dailyNoteSavePath",+ "dailyNoteTemplatePath",+ "docCreateSaveBox",+ "docCreateSavePath",+ "docCreateTemplatePath",+ "encrypted",+ "icon",+ "name",+ "refCreateSaveBox",+ "refCreateSavePath",+ "sort",+ "sortMode"+ ],+ "additionalProperties": false+ },+ "NotebookConfData": {+ "type": "object",+ "properties": {+ "box": {+ "type": "string"+ },+ "conf": {+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookConf"+ },+ {+ "type": "null"+ }+ ]+ },+ "name": {+ "type": "string"+ }+ },+ "required": [+ "box",+ "conf",+ "name"+ ],+ "additionalProperties": false+ },+ "NotebookConfPatchInput": {+ "type": "object",+ "properties": {+ "boxCrypt": {+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookEncryptionPatchInput"+ },+ {+ "type": "null"+ }+ ]+ },+ "closed": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "dailyNoteSavePath": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "dailyNoteTemplatePath": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "docCreateSaveBox": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "docCreateSavePath": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "docCreateTemplatePath": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "encrypted": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "icon": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "name": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "refCreateSaveBox": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "refCreateSavePath": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "sort": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ]+ },+ "sortMode": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "NotebookCryptoAutoLockRequestInput": {+ "type": "object",+ "properties": {+ "autoLockMinutes": {+ "type": "number"+ }+ },+ "required": [+ "autoLockMinutes"+ ],+ "additionalProperties": false+ },+ "NotebookCryptoBackupData": {+ "type": "object",+ "properties": {+ "file": {+ "type": "string"+ }+ },+ "required": [+ "file"+ ],+ "additionalProperties": false+ },+ "NotebookEncryption": {+ "type": "object",+ "properties": {+ "createdAt": {+ "type": "integer"+ },+ "metadata": {+ "type": "string"+ },+ "spec": {+ "type": "integer"+ },+ "wrapNonce": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "wrappedDEK": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "createdAt",+ "spec",+ "wrapNonce",+ "wrappedDEK"+ ],+ "additionalProperties": false+ },+ "NotebookEncryptionPatchInput": {+ "type": "object",+ "properties": {+ "createdAt": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ]+ },+ "metadata": {+ "anyOf": [+ {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "array",+ "items": {+ "type": "integer"+ }+ }+ ]+ },+ {+ "type": "null"+ }+ ]+ },+ "spec": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ]+ },+ "wrapNonce": {+ "anyOf": [+ {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "array",+ "items": {+ "type": "integer"+ }+ }+ ]+ },+ {+ "type": "null"+ }+ ]+ },+ "wrappedDEK": {+ "anyOf": [+ {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "array",+ "items": {+ "type": "integer"+ }+ }+ ]+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "NotebookIDRequestInput": {+ "type": "object",+ "properties": {+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "notebook"+ ],+ "additionalProperties": false+ },+ "NotebookInfo": {+ "type": "object",+ "properties": {+ "ctime": {+ "type": "integer"+ },+ "docCount": {+ "type": "integer"+ },+ "hCtime": {+ "type": "string"+ },+ "hMtime": {+ "type": "string"+ },+ "hSize": {+ "type": "string"+ },+ "id": {+ "type": "string"+ },+ "mtime": {+ "type": "integer"+ },+ "name": {+ "type": "string"+ },+ "size": {+ "type": "integer"+ }+ },+ "required": [+ "ctime",+ "docCount",+ "hCtime",+ "hMtime",+ "hSize",+ "id",+ "mtime",+ "name",+ "size"+ ],+ "additionalProperties": false+ },+ "NotebookInfoData": {+ "type": "object",+ "properties": {+ "boxInfo": {+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookInfo"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "boxInfo"+ ],+ "additionalProperties": false+ },+ "NotebookPasswordRequestInput": {+ "type": "object",+ "properties": {+ "password": {+ "type": "string"+ }+ },+ "required": [+ "password"+ ],+ "additionalProperties": false+ },+ "OpenNotebookRequestInput": {+ "type": "object",+ "properties": {+ "app": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "notebook"+ ],+ "additionalProperties": false+ },+ "OrderedListStartData": {+ "type": "object",+ "properties": {+ "found": {+ "type": "boolean"+ },+ "start": {+ "type": "integer"+ }+ },+ "required": [+ "found",+ "start"+ ],+ "additionalProperties": false+ },+ "PinnedDoc": {+ "type": "object",+ "properties": {+ "childrenSortMode": {+ "anyOf": [+ {+ "type": "integer"+ },+ {+ "type": "null"+ }+ ]+ },+ "icon": {+ "type": "string"+ },+ "id": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "notebook": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "subFileCount": {+ "type": "integer"+ },+ "unavailable": {+ "type": "boolean"+ }+ },+ "required": [+ "childrenSortMode",+ "icon",+ "id",+ "name",+ "notebook",+ "path",+ "subFileCount",+ "unavailable"+ ],+ "additionalProperties": false+ },+ "PrependBlockRequestInput": {+ "type": "object",+ "properties": {+ "data": {+ "type": "string"+ },+ "dataType": {+ "type": "string"+ },+ "parentID": {+ "type": "string"+ }+ },+ "required": [+ "data",+ "dataType",+ "parentID"+ ],+ "additionalProperties": false+ },+ "PublishedBlockInfo": {+ "type": "object",+ "properties": {+ "publishAccessRequired": {+ "type": "boolean",+ "enum": [+ true+ ]+ },+ "rootID": {+ "type": "string"+ },+ "rootIcon": {+ "type": "string"+ },+ "rootTitle": {+ "type": "string"+ },+ "rootTitleEmpty": {+ "type": "boolean"+ }+ },+ "required": [+ "publishAccessRequired",+ "rootID",+ "rootIcon",+ "rootTitle",+ "rootTitleEmpty"+ ],+ "additionalProperties": false+ },+ "RefDefs": {+ "type": "object",+ "properties": {+ "defIDs": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "refID": {+ "type": "string"+ }+ },+ "required": [+ "defIDs",+ "refID"+ ],+ "additionalProperties": false+ },+ "RefDefsData": {+ "type": "object",+ "properties": {+ "refDefs": {+ "type": "array",+ "items": {+ "$ref": "#/$defs/RefDefs"+ }+ }+ },+ "required": [+ "refDefs"+ ],+ "additionalProperties": false+ },+ "RefIDsData": {+ "type": "object",+ "properties": {+ "originalRefBlockIDs": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "refDefs": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/RefDefs"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "originalRefBlockIDs",+ "refDefs"+ ],+ "additionalProperties": false+ },+ "RefIDsRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "ids": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "RefTextQueryRequestInput": {+ "type": "object",+ "properties": {+ "anchor": {+ "type": "string"+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "anchor"+ ],+ "additionalProperties": false+ },+ "RemoveBookmarkRequestInput": {+ "type": "object",+ "properties": {+ "bookmark": {+ "type": "string"+ }+ },+ "required": [+ "bookmark"+ ],+ "additionalProperties": false+ },+ "RemoveTagRequestInput": {+ "type": "object",+ "properties": {+ "label": {+ "type": "string"+ }+ },+ "required": [+ "label"+ ],+ "additionalProperties": false+ },+ "RenameBookmarkRequestInput": {+ "type": "object",+ "properties": {+ "newBookmark": {+ "type": "string"+ },+ "oldBookmark": {+ "type": "string"+ }+ },+ "required": [+ "newBookmark",+ "oldBookmark"+ ],+ "additionalProperties": false+ },+ "RenameNotebookRequestInput": {+ "type": "object",+ "properties": {+ "name": {+ "type": "string"+ },+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "name",+ "notebook"+ ],+ "additionalProperties": false+ },+ "RenameTagRequestInput": {+ "type": "object",+ "properties": {+ "newLabel": {+ "type": "string"+ },+ "oldLabel": {+ "type": "string"+ }+ },+ "required": [+ "newLabel",+ "oldLabel"+ ],+ "additionalProperties": false+ },+ "ReorderData": {+ "type": "object",+ "properties": {+ "changed": {+ "type": "boolean"+ },+ "notebook": {+ "type": "string"+ },+ "parentPath": {+ "type": "string"+ }+ },+ "required": [+ "changed"+ ],+ "additionalProperties": false+ },+ "ReorderNotebooksRequestInput": {+ "type": "object",+ "properties": {+ "position": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "sourceIDs": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "targetID": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "SearchHistoryData": {+ "type": "object",+ "properties": {+ "histories": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "pageCount": {+ "type": "integer"+ },+ "totalCount": {+ "type": "integer"+ }+ },+ "required": [+ "histories",+ "pageCount",+ "totalCount"+ ],+ "additionalProperties": false+ },+ "SearchHistoryRequestInput": {+ "type": "object",+ "properties": {+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "op": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "page": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ },+ "query": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "type": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "additionalProperties": false+ },+ "SearchTagData": {+ "type": "object",+ "properties": {+ "k": {+ "type": "string"+ },+ "tags": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ },+ "required": [+ "k",+ "tags"+ ],+ "additionalProperties": false+ },+ "SearchTagRequestInput": {+ "type": "object",+ "properties": {+ "k": {+ "type": "string"+ }+ },+ "required": [+ "k"+ ],+ "additionalProperties": false+ },+ "SetBlockAttrsRequestInput": {+ "type": "object",+ "properties": {+ "attrs": {+ "type": "object",+ "additionalProperties": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "id": {+ "type": "string"+ }+ },+ "required": [+ "attrs",+ "id"+ ],+ "additionalProperties": false+ },+ "SetNotebookConfRequestInput": {+ "type": "object",+ "properties": {+ "conf": {+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookConfPatchInput"+ },+ {+ "type": "null"+ }+ ]+ },+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "notebook"+ ],+ "additionalProperties": false+ },+ "SetNotebookIconRequestInput": {+ "type": "object",+ "properties": {+ "icon": {+ "type": "string"+ },+ "notebook": {+ "type": "string"+ }+ },+ "required": [+ "icon",+ "notebook"+ ],+ "additionalProperties": false+ },+ "SetSnapshotMemoRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "memo": {+ "type": "string"+ }+ },+ "required": [+ "id",+ "memo"+ ],+ "additionalProperties": false+ },+ "SwapBlockRefRequestInput": {+ "type": "object",+ "properties": {+ "defID": {+ "type": "string"+ },+ "includeChildren": {+ "type": "boolean"+ },+ "refID": {+ "type": "string"+ }+ },+ "required": [+ "defID",+ "includeChildren",+ "refID"+ ],+ "additionalProperties": false+ },+ "TagData": {+ "type": "object",+ "properties": {+ "children": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/TagData"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "count": {+ "type": "integer"+ },+ "depth": {+ "type": "integer"+ },+ "label": {+ "type": "string"+ },+ "name": {+ "type": "string"+ },+ "type": {+ "type": "string"+ }+ },+ "required": [+ "children",+ "count",+ "depth",+ "label",+ "name",+ "type"+ ],+ "additionalProperties": false+ },+ "TailChildBlocksRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "ids": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "n": {+ "anyOf": [+ {+ "type": "number"+ },+ {+ "type": "null"+ }+ ]+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "TaskListMarkerRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "marker": {+ "type": "string"+ }+ },+ "required": [+ "id",+ "marker"+ ],+ "additionalProperties": false+ },+ "TransferBlockRefRequestInput": {+ "type": "object",+ "properties": {+ "fromID": {+ "type": "string"+ },+ "refIDs": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "reloadUI": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "toID": {+ "type": "string"+ }+ },+ "required": [+ "fromID",+ "toID"+ ],+ "additionalProperties": false+ },+ "TreeStatData": {+ "type": "object",+ "properties": {+ "containsEmbed": {+ "type": "boolean"+ },+ "embedStat": {+ "anyOf": [+ {+ "$ref": "#/$defs/EmbedStat"+ },+ {+ "type": "null"+ }+ ]+ },+ "reqId": {+ "$ref": "#/$defs/JSONValue"+ },+ "stat": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockStat"+ },+ {+ "type": "null"+ }+ ]+ },+ "statWithEmbed": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockStat"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "reqId",+ "stat"+ ],+ "additionalProperties": false+ },+ "TreeStatRequestInput": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string"+ },+ "ids": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "includeEmbed": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "reqId": {+ "anyOf": [+ {+ "$ref": "#/$defs/JSONValue"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },+ "UnfoldedParentData": {+ "type": "object",+ "properties": {+ "parentID": {+ "type": "string"+ }+ },+ "required": [+ "parentID"+ ],+ "additionalProperties": false+ },+ "UnlockNotebookRequestInput": {+ "type": "object",+ "properties": {+ "notebook": {+ "type": "string"+ },+ "password": {+ "type": "string"+ }+ },+ "required": [+ "notebook",+ "password"+ ],+ "additionalProperties": false+ },+ "UpdateBlockRequestInput": {+ "type": "object",+ "properties": {+ "data": {+ "type": "string"+ },+ "dataType": {+ "type": "string"+ },+ "id": {+ "type": "string"+ },+ "lockType": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "data",+ "dataType",+ "id"+ ],+ "additionalProperties": false+ },+ "UpdateChannelRequestInput": {+ "type": "object",+ "properties": {+ "updateChannel": {+ "type": "string"+ }+ },+ "required": [+ "updateChannel"+ ],+ "additionalProperties": false+ },+ "UpdatePinnedDocsRequestInput": {+ "type": "object",+ "properties": {+ "action": {+ "type": "string"+ },+ "after": {+ "type": "boolean"+ },+ "ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "targetID": {+ "type": "string"+ }+ },+ "required": [+ "action",+ "ids"+ ],+ "additionalProperties": false+ },+ "VirtualBlockRefRequestInput": {+ "type": "object",+ "properties": {+ "keywords": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ },+ "required": [+ "keywords"+ ],+ "additionalProperties": false+ },+ "WordCountData": {+ "type": "object",+ "properties": {+ "reqId": {+ "$ref": "#/$defs/JSONValue"+ },+ "stat": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockStat"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "reqId",+ "stat"+ ],+ "additionalProperties": false+ },+ "WorkspaceInfoData": {+ "type": "object",+ "properties": {+ "siyuanVer": {+ "type": "string"+ },+ "workspaceDir": {+ "type": "string"+ }+ },+ "required": [+ "siyuanVer",+ "workspaceDir"+ ],+ "additionalProperties": false+ }+ },+ "endpoints": [+ {+ "method": "GET",+ "path": "/api/system/bootProgress",+ "handler": "bootProgress",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BootProgressData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "GET",+ "path": "/api/system/version",+ "handler": "version",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "string"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/attr/batchGetBlockAttrs",+ "handler": "batchGetBlockAttrs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockIDsRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "object",+ "additionalProperties": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/attr/batchSetBlockAttrs",+ "handler": "batchSetBlockAttrs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BatchSetBlockAttrsRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/attr/getBlockAttrs",+ "handler": "getBlockAttrs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockIDRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/attr/getBookmarkLabels",+ "handler": "getBookmarkLabels",+ "body": "none",+ "request": {+ "$ref": "#/$defs/EmptyRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/attr/setBlockAttrs",+ "handler": "setBlockAttrs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/SetBlockAttrsRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/appendBlock",+ "handler": "appendBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/AppendBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/appendDailyNoteBlock",+ "handler": "appendDailyNoteBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DailyNoteBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/appendHeadingChildren",+ "handler": "appendHeadingChildren",+ "body": "json",+ "request": {+ "$ref": "#/$defs/AppendHeadingChildrenRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/batchAppendBlock",+ "handler": "batchAppendBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BatchParentBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/batchInsertBlock",+ "handler": "batchInsertBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BatchInsertBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/batchPrependBlock",+ "handler": "batchPrependBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BatchParentBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/batchUpdateBlock",+ "handler": "batchUpdateBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BatchUpdateBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/batchUpdateTaskListItemMarker",+ "handler": "batchUpdateTaskListItemMarker",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BatchTaskListMarkerRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/checkBlockExist",+ "handler": "checkBlockExist",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "boolean"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/checkBlockFold",+ "handler": "checkBlockFold",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockFoldData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/checkBlocksExist",+ "handler": "checkBlocksExist",+ "body": "json",+ "request": {+ "$ref": "#/$defs/CheckBlocksExistRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "boolean"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/deleteBlock",+ "handler": "deleteBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DeleteBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/foldBlock",+ "handler": "foldBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockIDRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockBreadcrumb",+ "handler": "getBlockBreadcrumb",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockBreadcrumbRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockPath"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockBreadcrumbChildren",+ "handler": "getBlockBreadcrumbChildren",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockBreadcrumbChildrenRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockBreadcrumbChildren"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockDOM",+ "handler": "getBlockDOM",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockDOMData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockDOMWithEmbed",+ "handler": "getBlockDOMWithEmbed",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockDOMData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockDOMs",+ "handler": "getBlockDOMs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlocksQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockDOMsWithEmbed",+ "handler": "getBlockDOMsWithEmbed",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlocksQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockDefIDsByRefText",+ "handler": "getBlockDefIDsByRefText",+ "body": "json",+ "request": {+ "$ref": "#/$defs/RefTextQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/RefDefsData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockIndex",+ "handler": "getBlockIndex",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "integer"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockInfo",+ "handler": "getBlockInfo",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockInfoRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockInfoData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1,+ 3+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ },+ {+ "type": "string"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockKramdown",+ "handler": "getBlockKramdown",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockKramdownRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockKramdownData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockKramdowns",+ "handler": "getBlockKramdowns",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlocksKramdownRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockRelevantIDs",+ "handler": "getBlockRelevantIDs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockRelevantData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockSiblingID",+ "handler": "getBlockSiblingID",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/BlockSiblingData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlockTreeInfos",+ "handler": "getBlockTreeInfos",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlocksQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTreeInfo"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlocksIndexes",+ "handler": "getBlocksIndexes",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlocksQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "additionalProperties": {+ "type": "integer"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getBlocksWordCount",+ "handler": "getBlocksWordCount",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlocksWordCountRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/WordCountData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getChildBlocks",+ "handler": "getChildBlocks",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/ChildBlock"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getContentWordCount",+ "handler": "getContentWordCount",+ "body": "json",+ "request": {+ "$ref": "#/$defs/ContentWordCountRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/WordCountData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getDOMText",+ "handler": "getDOMText",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DOMTextRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "string"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getDocBlocksOrders",+ "handler": "getDocBlocksOrders",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DocOrdersRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getDocInfo",+ "handler": "getDocInfo",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "$ref": "#/$defs/DocInfo"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getDocsInfo",+ "handler": "getDocsInfo",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DocsInfoRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/DocInfo"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getHeadingChildrenDOM",+ "handler": "getHeadingChildrenDOM",+ "body": "json",+ "request": {+ "$ref": "#/$defs/HeadingChildrenRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "string"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getHeadingChildrenIDs",+ "handler": "getHeadingChildrenIDs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockIDRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getHeadingDeleteTransaction",+ "handler": "getHeadingDeleteTransaction",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockIDRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getHeadingFoldTransaction",+ "handler": "getHeadingFoldTransaction",+ "body": "json",+ "request": {+ "$ref": "#/$defs/HeadingFoldRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getHeadingInsertTransaction",+ "handler": "getHeadingInsertTransaction",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockIDRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getOrderedListContinueStart",+ "handler": "getOrderedListContinueStart",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/OrderedListStartData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getRefIDs",+ "handler": "getRefIDs",+ "body": "json",+ "request": {+ "$ref": "#/$defs/RefIDsRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/RefIDsData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getRefIDsByFileAnnotationID",+ "handler": "getRefIDsByFileAnnotationID",+ "body": "json",+ "request": {+ "$ref": "#/$defs/FileAnnotationRefRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/RefDefsData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getRefText",+ "handler": "getRefText",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "string"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getTailChildBlocks",+ "handler": "getTailChildBlocks",+ "body": "json",+ "request": {+ "$ref": "#/$defs/TailChildBlocksRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/ChildBlock"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getTreeStat",+ "handler": "getTreeStat",+ "body": "json",+ "request": {+ "$ref": "#/$defs/TreeStatRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/TreeStatData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/getUnfoldedParentID",+ "handler": "getUnfoldedParentID",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockQueryRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/UnfoldedParentData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/insertBlock",+ "handler": "insertBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/InsertBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/moveBlock",+ "handler": "moveBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/MoveBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/moveOutlineHeading",+ "handler": "moveOutlineHeading",+ "body": "json",+ "request": {+ "$ref": "#/$defs/MoveBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/prependBlock",+ "handler": "prependBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/PrependBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/prependDailyNoteBlock",+ "handler": "prependDailyNoteBlock",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DailyNoteBlockRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/setBlockReminder",+ "handler": "setBlockReminder",+ "body": "json",+ "request": {+ "$ref": "#/$defs/BlockReminderRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/swapBlockRef",+ "handler": "swapBlockRef",+ "body": "json",+ "request": {+ "$ref": "#/$defs/SwapBlockRefRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false+ },+ {+ "type": "null"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },+ {+ "method": "POST",+ "path": "/api/block/transferBlockRef",+ "handler": "transferBlockRef",+ "body": "json",+ "request": {+ "$ref": "#/$defs/TransferBlockRefRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "null"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1+ ]+ },+ "data": {"anyOf": [{- "$ref": "#/$defs/TagData"+ "type": "object",+ "properties": {+ "closeTimeout": {+ "type": "number"+ }+ },+ "required": [+ "closeTimeout"+ ],+ "additionalProperties": false},{"type": "null"}]+ },+ "msg": {+ "type": "string"}},- {- "type": "null"- }- ]- },- "count": {- "type": "integer"- },- "depth": {- "type": "integer"- },- "label": {- "type": "string"- },- "name": {- "type": "string"- },- "type": {- "type": "string"- }- },- "required": [- "children",- "count",- "depth",- "label",- "name",- "type"- ],- "additionalProperties": false- },- "UnfoldedParentData": {- "type": "object",- "properties": {- "parentID": {- "type": "string"- }- },- "required": [- "parentID"- ],- "additionalProperties": false- },- "UpdateChannelRequestInput": {- "type": "object",- "properties": {- "updateChannel": {- "type": "string"- }- },- "required": [- "updateChannel"- ],- "additionalProperties": false- },- "UpdatePinnedDocsRequestInput": {- "type": "object",- "properties": {- "action": {- "type": "string"- },- "after": {- "type": "boolean"- },- "ids": {- "type": "array",- "items": {- "type": "string"- }- },- "targetID": {- "type": "string"- }- },- "required": [- "action",- "ids"- ],- "additionalProperties": false- },- "VirtualBlockRefRequestInput": {- "type": "object",- "properties": {- "keywords": {- "type": "array",- "items": {- "type": "string"+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true}- }- },- "required": [- "keywords"- ],- "additionalProperties": false+ ]+ }},- "WorkspaceInfoData": {- "type": "object",- "properties": {- "siyuanVer": {- "type": "string"- },- "workspaceDir": {- "type": "string"- }- },- "required": [- "siyuanVer",- "workspaceDir"- ],- "additionalProperties": false- }- },- "endpoints": [{- "method": "GET",- "path": "/api/system/bootProgress",- "handler": "bootProgress",- "body": "none",+ "method": "POST",+ "path": "/api/block/unfoldBlock",+ "handler": "unfoldBlock",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/BlockIDRequestInput"},"response": {"anyOf": [@@ -1197,7 +8698,7 @@]},"data": {- "$ref": "#/$defs/BootProgressData"+ "type": "null"},"msg": {"type": "string"@@ -1253,12 +8754,12 @@}},{- "method": "GET",- "path": "/api/system/version",- "handler": "version",- "body": "none",+ "method": "POST",+ "path": "/api/block/updateBlock",+ "handler": "updateBlock",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/UpdateBlockRequestInput"},"response": {"anyOf": [@@ -1272,7 +8773,24 @@]},"data": {- "type": "string"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -1329,11 +8847,11 @@},{"method": "POST",- "path": "/api/attr/batchGetBlockAttrs",- "handler": "batchGetBlockAttrs",+ "path": "/api/block/updateTaskListItemMarker",+ "handler": "updateTaskListItemMarker","body": "json","request": {- "$ref": "#/$defs/BlockIDsRequestInput"+ "$ref": "#/$defs/TaskListMarkerRequestInput"},"response": {"anyOf": [@@ -1347,20 +8865,24 @@]},"data": {- "type": "object",- "additionalProperties": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "type": "string"- }- },- {- "type": "null"+ "anyOf": [+ {+ "type": "array",+ "items": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockTransaction"+ },+ {+ "type": "null"+ }+ ]}- ]- }+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -1417,11 +8939,11 @@},{"method": "POST",- "path": "/api/attr/batchSetBlockAttrs",- "handler": "batchSetBlockAttrs",+ "path": "/api/bookmark/removeBookmark",+ "handler": "removeBookmark","body": "json","request": {- "$ref": "#/$defs/BatchSetBlockAttrsRequestInput"+ "$ref": "#/$defs/RemoveBookmarkRequestInput"},"response": {"anyOf": [@@ -1492,11 +9014,11 @@},{"method": "POST",- "path": "/api/attr/getBlockAttrs",- "handler": "getBlockAttrs",+ "path": "/api/bookmark/renameBookmark",+ "handler": "renameBookmark","body": "json","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/RenameBookmarkRequestInput"},"response": {"anyOf": [@@ -1510,10 +9032,7 @@]},"data": {- "type": "object",- "additionalProperties": {- "type": "string"- }+ "type": "null"},"msg": {"type": "string"@@ -1570,8 +9089,8 @@},{"method": "POST",- "path": "/api/attr/getBookmarkLabels",- "handler": "getBookmarkLabels",+ "path": "/api/filetree/getPinnedDocs",+ "handler": "getPinnedDocs","body": "none","request": {"$ref": "#/$defs/EmptyRequestInput"@@ -1588,17 +9107,10 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "type": "string"- }- },- {- "type": "null"- }- ]+ "type": "array",+ "items": {+ "$ref": "#/$defs/PinnedDoc"+ }},"msg": {"type": "string"@@ -1655,11 +9167,11 @@},{"method": "POST",- "path": "/api/attr/setBlockAttrs",- "handler": "setBlockAttrs",+ "path": "/api/filetree/updatePinnedDocs",+ "handler": "updatePinnedDocs","body": "json","request": {- "$ref": "#/$defs/SetBlockAttrsRequestInput"+ "$ref": "#/$defs/UpdatePinnedDocsRequestInput"},"response": {"anyOf": [@@ -1730,11 +9242,11 @@},{"method": "POST",- "path": "/api/block/appendHeadingChildren",- "handler": "appendHeadingChildren",- "body": "json",+ "path": "/api/history/clearWorkspaceHistory",+ "handler": "clearWorkspaceHistory",+ "body": "none","request": {- "$ref": "#/$defs/AppendHeadingChildrenRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -1805,11 +9317,11 @@},{"method": "POST",- "path": "/api/block/checkBlockExist",- "handler": "checkBlockExist",- "body": "json",+ "path": "/api/history/reindexHistory",+ "handler": "reindexHistory",+ "body": "none","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -1823,7 +9335,7 @@]},"data": {- "type": "boolean"+ "type": "null"},"msg": {"type": "string"@@ -1880,11 +9392,11 @@},{"method": "POST",- "path": "/api/block/checkBlockFold",- "handler": "checkBlockFold",+ "path": "/api/history/searchHistory",+ "handler": "searchHistory","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/SearchHistoryRequestInput"},"response": {"anyOf": [@@ -1898,7 +9410,7 @@]},"data": {- "$ref": "#/$defs/BlockFoldData"+ "$ref": "#/$defs/SearchHistoryData"},"msg": {"type": "string"@@ -1955,11 +9467,11 @@},{"method": "POST",- "path": "/api/block/getBlockIndex",- "handler": "getBlockIndex",+ "path": "/api/notebook/changeMasterPassword",+ "handler": "changeMasterPassword","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/ChangeMasterPasswordRequestInput"},"response": {"anyOf": [@@ -1973,7 +9485,7 @@]},"data": {- "type": "integer"+ "type": "null"},"msg": {"type": "string"@@ -2030,11 +9542,11 @@},{"method": "POST",- "path": "/api/block/getBlockInfo",- "handler": "getBlockInfo",+ "path": "/api/notebook/changeSortNotebook",+ "handler": "changeSortNotebook","body": "json","request": {- "$ref": "#/$defs/BlockInfoRequestInput"+ "$ref": "#/$defs/ChangeSortNotebookRequestInput"},"response": {"anyOf": [@@ -2048,7 +9560,7 @@]},"data": {- "$ref": "#/$defs/BlockInfoData"+ "type": "null"},"msg": {"type": "string"@@ -2067,8 +9579,7 @@"code": {"type": "integer","enum": [- -1,- 3+ -1]},"data": {@@ -2087,9 +9598,6 @@},{"type": "null"- },- {- "type": "string"}]},@@ -2109,11 +9617,11 @@},{"method": "POST",- "path": "/api/block/getBlockRelevantIDs",- "handler": "getBlockRelevantIDs",+ "path": "/api/notebook/closeNotebook",+ "handler": "closeNotebook","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/CloseNotebookRequestInput"},"response": {"anyOf": [@@ -2127,7 +9635,7 @@]},"data": {- "$ref": "#/$defs/BlockRelevantData"+ "type": "null"},"msg": {"type": "string"@@ -2184,11 +9692,11 @@},{"method": "POST",- "path": "/api/block/getBlockSiblingID",- "handler": "getBlockSiblingID",+ "path": "/api/notebook/createEncryptedNotebook",+ "handler": "createEncryptedNotebook","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/CreateEncryptedNotebookRequestInput"},"response": {"anyOf": [@@ -2202,7 +9710,7 @@]},"data": {- "$ref": "#/$defs/BlockSiblingData"+ "$ref": "#/$defs/CreateNotebookData"},"msg": {"type": "string"@@ -2259,11 +9767,11 @@},{"method": "POST",- "path": "/api/block/getBlocksIndexes",- "handler": "getBlocksIndexes",+ "path": "/api/notebook/createNotebook",+ "handler": "createNotebook","body": "json","request": {- "$ref": "#/$defs/BlocksQueryRequestInput"+ "$ref": "#/$defs/CreateNotebookRequestInput"},"response": {"anyOf": [@@ -2277,17 +9785,7 @@]},"data": {- "anyOf": [- {- "type": "object",- "additionalProperties": {- "type": "integer"- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/CreateNotebookData"},"msg": {"type": "string"@@ -2344,11 +9842,11 @@},{"method": "POST",- "path": "/api/block/getDOMText",- "handler": "getDOMText",- "body": "json",+ "path": "/api/notebook/disableEncryptedNotebooks",+ "handler": "disableEncryptedNotebooks",+ "body": "none","request": {- "$ref": "#/$defs/DOMTextRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -2362,7 +9860,7 @@]},"data": {- "type": "string"+ "type": "null"},"msg": {"type": "string"@@ -2419,11 +9917,11 @@},{"method": "POST",- "path": "/api/block/getDocBlocksOrders",- "handler": "getDocBlocksOrders",+ "path": "/api/notebook/enableEncryptedNotebooks",+ "handler": "enableEncryptedNotebooks","body": "json","request": {- "$ref": "#/$defs/DocOrdersRequestInput"+ "$ref": "#/$defs/NotebookPasswordRequestInput"},"response": {"anyOf": [@@ -2437,17 +9935,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "type": "string"- }- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -2504,11 +9992,11 @@},{"method": "POST",- "path": "/api/block/getHeadingChildrenDOM",- "handler": "getHeadingChildrenDOM",- "body": "json",+ "path": "/api/notebook/exportNotebookCryptoBackup",+ "handler": "exportNotebookCryptoBackup",+ "body": "none","request": {- "$ref": "#/$defs/HeadingChildrenRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -2522,7 +10010,7 @@]},"data": {- "type": "string"+ "$ref": "#/$defs/NotebookCryptoBackupData"},"msg": {"type": "string"@@ -2579,11 +10067,11 @@},{"method": "POST",- "path": "/api/block/getHeadingChildrenIDs",- "handler": "getHeadingChildrenIDs",- "body": "json",+ "path": "/api/notebook/getEncryptedNotebookStatus",+ "handler": "getEncryptedNotebookStatus",+ "body": "none","request": {- "$ref": "#/$defs/BlockIDRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -2597,17 +10085,7 @@]},"data": {- "anyOf": [- {- "type": "array",- "items": {- "type": "string"- }- },- {- "type": "null"- }- ]+ "$ref": "#/$defs/EncryptedNotebookStatusData"},"msg": {"type": "string"@@ -2664,11 +10142,11 @@},{"method": "POST",- "path": "/api/block/getUnfoldedParentID",- "handler": "getUnfoldedParentID",+ "path": "/api/notebook/getNotebookConf",+ "handler": "getNotebookConf","body": "json","request": {- "$ref": "#/$defs/BlockQueryRequestInput"+ "$ref": "#/$defs/CloseNotebookRequestInput"},"response": {"anyOf": [@@ -2682,7 +10160,7 @@]},"data": {- "$ref": "#/$defs/UnfoldedParentData"+ "$ref": "#/$defs/NotebookConfData"},"msg": {"type": "string"@@ -2739,11 +10217,11 @@},{"method": "POST",- "path": "/api/bookmark/removeBookmark",- "handler": "removeBookmark",+ "path": "/api/notebook/getNotebookInfo",+ "handler": "getNotebookInfo","body": "json","request": {- "$ref": "#/$defs/RemoveBookmarkRequestInput"+ "$ref": "#/$defs/NotebookIDRequestInput"},"response": {"anyOf": [@@ -2757,7 +10235,7 @@]},"data": {- "type": "null"+ "$ref": "#/$defs/NotebookInfoData"},"msg": {"type": "string"@@ -2814,11 +10292,11 @@},{"method": "POST",- "path": "/api/bookmark/renameBookmark",- "handler": "renameBookmark",- "body": "json",+ "path": "/api/notebook/importNotebookCryptoBackup",+ "handler": "importNotebookCryptoBackup",+ "body": "multipart","request": {- "$ref": "#/$defs/RenameBookmarkRequestInput"+ "$ref": "#/$defs/ImportNotebookCryptoBackupRequestInput"},"response": {"anyOf": [@@ -2889,11 +10367,11 @@},{"method": "POST",- "path": "/api/filetree/getPinnedDocs",- "handler": "getPinnedDocs",- "body": "none",+ "path": "/api/notebook/lockNotebook",+ "handler": "lockNotebook",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/NotebookIDRequestInput"},"response": {"anyOf": [@@ -2907,10 +10385,7 @@]},"data": {- "type": "array",- "items": {- "$ref": "#/$defs/PinnedDoc"- }+ "type": "null"},"msg": {"type": "string"@@ -2967,11 +10442,11 @@},{"method": "POST",- "path": "/api/filetree/updatePinnedDocs",- "handler": "updatePinnedDocs",- "body": "json",+ "path": "/api/notebook/lsNotebooks",+ "handler": "lsNotebooks",+ "body": "legacyOptional","request": {- "$ref": "#/$defs/UpdatePinnedDocsRequestInput"+ "$ref": "#/$defs/ListNotebooksRequestInput"},"response": {"anyOf": [@@ -2985,7 +10460,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/ListNotebooksData"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -3042,11 +10524,11 @@},{"method": "POST",- "path": "/api/history/clearWorkspaceHistory",- "handler": "clearWorkspaceHistory",- "body": "none",+ "path": "/api/notebook/openNotebook",+ "handler": "openNotebook",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/OpenNotebookRequestInput"},"response": {"anyOf": [@@ -3117,11 +10599,11 @@},{"method": "POST",- "path": "/api/history/reindexHistory",- "handler": "reindexHistory",- "body": "none",+ "path": "/api/notebook/removeNotebook",+ "handler": "removeNotebook",+ "body": "json","request": {- "$ref": "#/$defs/EmptyRequestInput"+ "$ref": "#/$defs/NotebookIDRequestInput"},"response": {"anyOf": [@@ -3192,11 +10674,11 @@},{"method": "POST",- "path": "/api/history/searchHistory",- "handler": "searchHistory",+ "path": "/api/notebook/renameNotebook",+ "handler": "renameNotebook","body": "json","request": {- "$ref": "#/$defs/SearchHistoryRequestInput"+ "$ref": "#/$defs/RenameNotebookRequestInput"},"response": {"anyOf": [@@ -3210,7 +10692,7 @@]},"data": {- "$ref": "#/$defs/SearchHistoryData"+ "type": "null"},"msg": {"type": "string"@@ -3267,11 +10749,11 @@},{"method": "POST",- "path": "/api/notebook/changeSortNotebook",- "handler": "changeSortNotebook",- "body": "json",+ "path": "/api/notebook/reorder",+ "handler": "reorderNotebooks",+ "body": "structJSON","request": {- "$ref": "#/$defs/ChangeSortNotebookRequestInput"+ "$ref": "#/$defs/ReorderNotebooksRequestInput"},"response": {"anyOf": [@@ -3285,7 +10767,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/ReorderData"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -3323,6 +10812,16 @@},{"type": "null"+ },+ {+ "anyOf": [+ {+ "$ref": "#/$defs/ReorderData"+ },+ {+ "type": "null"+ }+ ]}]},@@ -3342,11 +10841,11 @@},{"method": "POST",- "path": "/api/notebook/closeNotebook",- "handler": "closeNotebook",+ "path": "/api/notebook/setNotebookConf",+ "handler": "setNotebookConf","body": "json","request": {- "$ref": "#/$defs/CloseNotebookRequestInput"+ "$ref": "#/$defs/SetNotebookConfRequestInput"},"response": {"anyOf": [@@ -3360,7 +10859,14 @@]},"data": {- "type": "null"+ "anyOf": [+ {+ "$ref": "#/$defs/NotebookConf"+ },+ {+ "type": "null"+ }+ ]},"msg": {"type": "string"@@ -3417,11 +10923,11 @@},{"method": "POST",- "path": "/api/notebook/createNotebook",- "handler": "createNotebook",+ "path": "/api/notebook/setNotebookCryptoAutoLock",+ "handler": "setNotebookCryptoAutoLock","body": "json","request": {- "$ref": "#/$defs/CreateNotebookRequestInput"+ "$ref": "#/$defs/NotebookCryptoAutoLockRequestInput"},"response": {"anyOf": [@@ -3435,7 +10941,7 @@]},"data": {- "$ref": "#/$defs/CreateNotebookData"+ "type": "null"},"msg": {"type": "string"@@ -3492,11 +10998,11 @@},{"method": "POST",- "path": "/api/notebook/lsNotebooks",- "handler": "lsNotebooks",- "body": "legacyOptional",+ "path": "/api/notebook/setNotebookIcon",+ "handler": "setNotebookIcon",+ "body": "json","request": {- "$ref": "#/$defs/ListNotebooksRequestInput"+ "$ref": "#/$defs/SetNotebookIconRequestInput"},"response": {"anyOf": [@@ -3510,14 +11016,7 @@]},"data": {- "anyOf": [- {- "$ref": "#/$defs/ListNotebooksData"- },- {- "type": "null"- }- ]+ "type": "null"},"msg": {"type": "string"@@ -3574,11 +11073,11 @@},{"method": "POST",- "path": "/api/notebook/removeNotebook",- "handler": "removeNotebook",- "body": "json",+ "path": "/api/notebook/touchEncryptedNotebooks",+ "handler": "touchEncryptedNotebooks",+ "body": "none","request": {- "$ref": "#/$defs/NotebookIDRequestInput"+ "$ref": "#/$defs/EmptyRequestInput"},"response": {"anyOf": [@@ -3649,11 +11148,11 @@},{"method": "POST",- "path": "/api/notebook/renameNotebook",- "handler": "renameNotebook",+ "path": "/api/notebook/unlockAndOpenNotebook",+ "handler": "unlockAndOpenNotebook","body": "json","request": {- "$ref": "#/$defs/RenameNotebookRequestInput"+ "$ref": "#/$defs/UnlockNotebookRequestInput"},"response": {"anyOf": [@@ -3724,11 +11223,11 @@},{"method": "POST",- "path": "/api/notebook/setNotebookIcon",- "handler": "setNotebookIcon",+ "path": "/api/notebook/unlockNotebook",+ "handler": "unlockNotebook","body": "json","request": {- "$ref": "#/$defs/SetNotebookIconRequestInput"+ "$ref": "#/$defs/UnlockNotebookRequestInput"},"response": {"anyOf": [diff --git a/kernel/apicontract/typescript.go b/kernel/apicontract/typescript.goindex 520b528e81..4d17476641 100644--- a/kernel/apicontract/typescript.go+++ b/kernel/apicontract/typescript.go@@ -19,6 +19,9 @@ func sortedKeys[V any](values map[string]V) []string {func quote(value string) string { data, _ := json.Marshal(value); return string(data) }func (b *Bundle) typeScript(schema *Schema) string {+ if schema.Format == "binary" {+ return "Blob"+ }if schema.Ref != "" {return strings.TrimPrefix(schema.Ref, "#/$defs/")}@@ -76,6 +79,9 @@ func (b *Bundle) typeScript(schema *Schema) string {return "Array<" + b.typeScript(schema.Items) + ">"case "object":if additional, ok := schema.AdditionalProperties.(*Schema); ok {+ if additional.Ref == "#/$defs/JSONValue" {+ return "{ [key: string]: JSONValue }"+ }return "Record<string, " + b.typeScript(additional) + ">"}if len(schema.Properties) == 0 {@@ -162,7 +168,12 @@ export interface APILegacyResponse {}type APIContract = {request: unknown; response: unknown; body: string};-type APIRequestArgs<C extends APIContract> = C["body"] extends "json"+export interface APIFormData<Request> extends FormData {+ readonly apiRequest: Request;+}+type APIRequestArgs<C extends APIContract> = C["body"] extends "multipart"+ ? [data: APIFormData<C["request"]>]+ : C["body"] extends "json" | "structJSON"? [data: C["request"]]: [data?: C["request"] | null];type NonNegative<C extends number> = C extends C ? ` + "`${C}` extends `-${string}`" + ` ? never : C : never;