Skip to content

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

:sparkles: Extend typed contracts to core kernel APIs https://github.com/siyuan-note/siyuan/issues/19378

Daniel257cf41c1407
diff --git a/.github/workflows/api-contracts.yml b/.github/workflows/api-contracts.yml
index 5806066ce2..ebcf27438d 100644
--- a/.github/workflows/api-contracts.yml
+++ b/.github/workflows/api-contracts.yml
@@ -43,7 +43,7 @@ jobs:
run: go test ./apicontract/...
working-directory: kernel
- name: Test actual API responses and compatibility
- run: go test -tags "fts5 sqlcipher" ./api -run "TestAPIContract|TestBlockAttrsRespectPublishAccess|TestGetBlockInfoRecovery|TestGetBlockInfoPublishAccess|TestListNotebooksSortsBySubDocCount" -count=1
+ run: go test -tags "fts5 sqlcipher" ./api -run "TestAPIContract|TestBlockAttrsRespectPublishAccess|TestGetBlockInfoRecovery|TestGetBlockInfoPublishAccess|TestListNotebooksSortsBySubDocCount|TestContract.*NotebookResponseLease" -count=1
working-directory: kernel
- name: Test frontend transport behavior
run: pnpm exec tsx --test src/util/fetch.test.ts src/util/fetchTimeout.test.ts
diff --git a/app/src/block/util.ts b/app/src/block/util.ts
index 66fb6a0ed1..d63fdfcf0a 100644
--- a/app/src/block/util.ts
+++ b/app/src/block/util.ts
@@ -79,6 +79,9 @@ export const getCancelSBOperations = async (nodeElement: Element, options: {
id,
notebook: options.notebookID,
});
+ if (idData.code !== 0) {
+ throw new Error(idData.msg);
+ }
previousId = idData.data.previous;
parentID = idData.data.parent;
} else {
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index d36d9732b2..8576d99bbf 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -1098,8 +1098,10 @@ export const zoomOut = (options: {
let focusElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.focusId}"]`);
if (!focusElement) {
const unfoldResponse = await fetchSyncPost("/api/block/getUnfoldedParentID", {id: options.focusId});
- options.focusId = unfoldResponse.data.parentID;
- focusElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${unfoldResponse.data.parentID}"]`);
+ if (unfoldResponse.code === 0) {
+ options.focusId = unfoldResponse.data.parentID;
+ focusElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${unfoldResponse.data.parentID}"]`);
+ }
}
if (focusElement) {
// 退出聚焦后块在折叠中 https://github.com/siyuan-note/siyuan/issues/10746
diff --git a/app/src/protyle/util/blockFold.ts b/app/src/protyle/util/blockFold.ts
index c032c7361b..15a79448a9 100644
--- a/app/src/protyle/util/blockFold.ts
+++ b/app/src/protyle/util/blockFold.ts
@@ -319,6 +319,9 @@ const foldBlocksRecursively0 = async (protyle: IProtyle, nodeElements: Element[]
id: element.getAttribute("data-node-id"),
removeFoldAttr: false,
});
+ if (response.code !== 0) {
+ throw new Error(response.msg);
+ }
fullHTML = response.data;
} else if (element.querySelector('[data-type="NodeHeading"][fold="1"]')) {
const response = await fetchSyncPost("/api/block/getBlockDOM", {
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index ef844c22fb..200f617f42 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -187,10 +187,13 @@ const cancelDetachedSourceSB = async (nodeElement: Element, excludedChildIDs: Se
id: nodeElement.getAttribute("data-node-id"),
notebook: notebookID,
});
+ if (relevantIDs.code !== 0) {
+ throw new Error(relevantIDs.msg);
+ }
const operationData = await getCancelSBOperations(nodeElement, {
notebookID,
- previousID: relevantIDs?.data?.previousID,
- parentID: relevantIDs?.data?.parentID || sourceElement?.getAttribute(DRAG_SOURCE_ROOT_ID) || "",
+ previousID: relevantIDs.data.previousID,
+ parentID: relevantIDs.data.parentID || sourceElement?.getAttribute(DRAG_SOURCE_ROOT_ID) || "",
fallbackParentID: sourceElement?.getAttribute(DRAG_SOURCE_ROOT_ID) || "",
excludedChildIDs,
});
diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.ts
index 33d12171d7..867428aa4e 100644
--- a/app/src/protyle/wysiwyg/commonHotkey.ts
+++ b/app/src/protyle/wysiwyg/commonHotkey.ts
@@ -357,6 +357,9 @@ export const duplicateBlock = async (nodeElements: Element[], protyle: IProtyle)
id: item.getAttribute("data-node-id"),
removeFoldAttr: false,
});
+ if (responseHTML.code !== 0) {
+ throw new Error(responseHTML.msg);
+ }
const foldElement = document.createElement("template");
foldElement.innerHTML = normalizeHTMLAssetIFrameBlockDOM(responseHTML.data);
let previousID = newId;
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 81dce7acc7..490ca11f9a 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -834,6 +834,9 @@ export class WYSIWYG {
id: item.getAttribute("data-node-id"),
removeFoldAttr: false
});
+ if (response.code !== 0) {
+ return;
+ }
itemHTML = response.data;
} else if (item.getAttribute("data-type") !== "NodeBlockQueryEmbed" && item.querySelector('[data-type="NodeHeading"][fold="1"]')) {
needClipboardWrite = true;
@@ -3173,6 +3176,10 @@ export class WYSIWYG {
id: item.getAttribute("data-node-id"),
removeFoldAttr: false
});
+ if (response.code !== 0) {
+ clearAutoSelectedBlock();
+ return;
+ }
itemHTML = response.data;
const deleteResponse = await fetchSyncPost("/api/block/getHeadingDeleteTransaction", {
id: item.getAttribute("data-node-id"),
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index ab053600ab..a8f333f3bf 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -2023,6 +2023,9 @@ export const turnListsRecursively = async (options: {
id: nodeElement.getAttribute("data-node-id"),
notebook: options.protyle.notebookId,
});
+ if (response.code !== 0) {
+ throw new Error(response.msg);
+ }
previousId = response.data.previousID;
}
return {
@@ -2174,6 +2177,9 @@ export const turnsOneInto = async (options: {
id: options.id,
notebook: options.protyle.notebookId,
});
+ if (response.code !== 0) {
+ throw new Error(response.msg);
+ }
previousId = response.data.previousID;
}
const parentId = getEmbedChildOperationParentID(options.nodeElement) ||
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.ts
index c40a98ee39..723223568b 100644
--- a/app/src/types/api/index.d.ts
+++ b/app/src/types/api/index.d.ts
@@ -1,29 +1,81 @@
// 此文件由内核契约生成,请运行 pnpm run api:generate 更新。
+export type AppendHeadingChildrenRequestInput = { "childrenDOM": string; "id": string; };
+
+export type AutoLaunchRequestInput = { "autoLaunch": number; };
+
+export type BatchSetBlockAttrsRequestInput = { "blockAttrs": Array<SetBlockAttrsRequestInput>; };
+
+export type BlockFoldData = { "isFolded": boolean; "isRoot": boolean; };
+
export type BlockIDRequestInput = { "id": string; };
+export type BlockIDsRequestInput = { "ids": Array<string>; };
+
export type BlockInfoData = (FullBlockInfo & { "publishAccessRequired"?: never; }) | (PublishedBlockInfo & { "box"?: never; "path"?: never; "rootChildID"?: never; });
export type BlockInfoRequestInput = { "id": string; "ids"?: Array<string> | null; "notebook"?: string | null; };
+export type BlockQueryRequestInput = { "id": string; "ids"?: Array<string> | null; "notebook"?: string | null; };
+
+export type BlockRelevantData = { "nextID": string; "parentID": string; "previousID": string; };
+
+export type BlockSiblingData = { "next": string; "parent": string; "previous": string; };
+
+export type BlocksQueryRequestInput = { "id"?: string | null; "ids": Array<string>; "notebook"?: string | null; };
+
+export type BootProgressData = { "details": string; "progress": number; };
+
export type CheckSnapshotData = { "changed": boolean; };
export type CreateSnapshotData = { "created": boolean; "id": string; };
export type CreateSnapshotRequestInput = { "memo"?: string; };
+export type DOMTextRequestInput = { "dom": string; };
+
+export type DocOrdersRequestInput = { "id": string; };
+
+export type DownloadInstallPkgRequestInput = { "downloadInstallPkg": boolean; };
+
+export type EditorReadOnlyRequestInput = { "readonly": boolean; };
+
export type EmptyRequestInput = Record<string, never>;
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 ListNotebooksData = { "boxDocEnabled": boolean; "notebooks": Array<Notebook | null> | null; };
export type ListNotebooksRequestInput = { "flashcard"?: boolean | null; };
+export type LockScreenRequestInput = { "lockScreenMode": number; };
+
+export type NetworkData = { "proxy": NetworkProxy | null; };
+
+export type NetworkProxy = { "host": string; "port": string; "scheme": string; };
+
+export type NetworkProxyInput = { "host": string; "port": string; "scheme": string; };
+
+export type NetworkServeRequestInput = { "networkServe": boolean; };
+
+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 PublishedBlockInfo = { "publishAccessRequired": true; "rootID": string; "rootIcon": string; "rootTitle": string; "rootTitleEmpty": boolean; };
+export type RemoveBookmarkRequestInput = { "bookmark": string; };
+
+export type RemoveTagRequestInput = { "label": string; };
+
+export type RenameBookmarkRequestInput = { "newBookmark": string; "oldBookmark": string; };
+
+export type RenameTagRequestInput = { "newLabel": string; "oldLabel": string; };
+
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; };
@@ -36,6 +88,16 @@ export type SetBlockAttrsRequestInput = { "attrs": Record<string, string | null>
export type SetSnapshotMemoRequestInput = { "id": string; "memo": string; };
+export type TagData = { "children": Array<TagData | null> | null; "count": number; "depth": number; "label": string; "name": string; "type": string; };
+
+export type UnfoldedParentData = { "parentID": string; };
+
+export type UpdateChannelRequestInput = { "updateChannel": string; };
+
+export type VirtualBlockRefRequestInput = { "keywords": Array<string>; };
+
+export type WorkspaceInfoData = { "siyuanVer": string; "workspaceDir": string; };
+
export type APILegacyGETPath =
"/api/ai/mcp/oauth/callback/:flowID" |
"/api/icon/getDynamicIcon" |
@@ -45,7 +107,6 @@ export type APILegacyGETPath =
"/api/plugin" |
"/api/plugin/rpc" |
"/api/plugin/rpc/:name" |
- "/api/system/bootProgress" |
"/api/system/bootProgressSSE" |
"/api/system/getBootAppearance" |
"/api/system/getCaptcha" |
@@ -59,6 +120,11 @@ export type APILegacyGETPath =
"/ws/plugin/rpc/:name";
export interface APIGETRoutes {
+ "/api/system/bootProgress": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": BootProgressData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
"/api/system/version": {
request: EmptyRequestInput;
response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
@@ -128,9 +194,6 @@ export type APILegacyPOSTPath =
"/api/asset/upload" |
"/api/asset/uploadCloud" |
"/api/asset/uploadCloudByAssetsPaths" |
- "/api/attr/batchGetBlockAttrs" |
- "/api/attr/batchSetBlockAttrs" |
- "/api/attr/getBookmarkLabels" |
"/api/attr/resetBlockAttrs" |
"/api/av/addAttributeViewBlocks" |
"/api/av/addAttributeViewKey" |
@@ -213,14 +276,11 @@ export type APILegacyPOSTPath =
"/api/bazaar/updateBazaarPackage" |
"/api/block/appendBlock" |
"/api/block/appendDailyNoteBlock" |
- "/api/block/appendHeadingChildren" |
"/api/block/batchAppendBlock" |
"/api/block/batchInsertBlock" |
"/api/block/batchPrependBlock" |
"/api/block/batchUpdateBlock" |
"/api/block/batchUpdateTaskListItemMarker" |
- "/api/block/checkBlockExist" |
- "/api/block/checkBlockFold" |
"/api/block/checkBlockRef" |
"/api/block/checkBlocksExist" |
"/api/block/deleteBlock" |
@@ -232,23 +292,15 @@ export type APILegacyPOSTPath =
"/api/block/getBlockDOMs" |
"/api/block/getBlockDOMsWithEmbed" |
"/api/block/getBlockDefIDsByRefText" |
- "/api/block/getBlockIndex" |
"/api/block/getBlockKramdown" |
"/api/block/getBlockKramdowns" |
- "/api/block/getBlockRelevantIDs" |
- "/api/block/getBlockSiblingID" |
"/api/block/getBlockTreeInfos" |
- "/api/block/getBlocksIndexes" |
"/api/block/getBlocksWordCount" |
"/api/block/getChildBlocks" |
"/api/block/getContentWordCount" |
- "/api/block/getDOMText" |
- "/api/block/getDocBlocksOrders" |
"/api/block/getDocHeadingLevelTransaction" |
"/api/block/getDocInfo" |
"/api/block/getDocsInfo" |
- "/api/block/getHeadingChildrenDOM" |
- "/api/block/getHeadingChildrenIDs" |
"/api/block/getHeadingDeleteTransaction" |
"/api/block/getHeadingFoldTransaction" |
"/api/block/getHeadingInsertTransaction" |
@@ -260,7 +312,6 @@ export type APILegacyPOSTPath =
"/api/block/getRefText" |
"/api/block/getTailChildBlocks" |
"/api/block/getTreeStat" |
- "/api/block/getUnfoldedParentID" |
"/api/block/insertBlock" |
"/api/block/moveBlock" |
"/api/block/moveOutlineHeading" |
@@ -273,8 +324,6 @@ export type APILegacyPOSTPath =
"/api/block/updateBlock" |
"/api/block/updateTaskListItemMarker" |
"/api/bookmark/getBookmark" |
- "/api/bookmark/removeBookmark" |
- "/api/bookmark/renameBookmark" |
"/api/broadcast/getChannelInfo" |
"/api/broadcast/getChannels" |
"/api/broadcast/postMessage" |
@@ -375,14 +424,12 @@ export type APILegacyPOSTPath =
"/api/graph/resetGraph" |
"/api/graph/resetLocalGraph" |
"/api/graph/setGraphConf" |
- "/api/history/clearWorkspaceHistory" |
"/api/history/createAssetHistory" |
"/api/history/createDocHistory" |
"/api/history/diffDocVersions" |
"/api/history/getDocHistoryContent" |
"/api/history/getHistoryItems" |
"/api/history/getNotebookHistory" |
- "/api/history/reindexHistory" |
"/api/history/rollbackAssetsHistory" |
"/api/history/rollbackAttributeViewHistory" |
"/api/history/rollbackDocHistory" |
@@ -507,22 +554,17 @@ export type APILegacyPOSTPath =
"/api/search/searchWidget" |
"/api/search/semanticSearchBlock" |
"/api/search/updateEmbedBlock" |
- "/api/setting/addVirtualBlockRefExclude" |
- "/api/setting/addVirtualBlockRefInclude" |
"/api/setting/getBootAppearances" |
"/api/setting/getCloudUser" |
- "/api/setting/getPandocBin" |
"/api/setting/getPublish" |
"/api/setting/login2faCloudUser" |
"/api/setting/logoutCloudUser" |
- "/api/setting/refreshVirtualBlockRef" |
"/api/setting/setAI" |
"/api/setting/setAppearance" |
"/api/setting/setBazaar" |
"/api/setting/setBazaarPetalDisabled" |
"/api/setting/setBootAppearance" |
"/api/setting/setEditor" |
- "/api/setting/setEditorReadOnly" |
"/api/setting/setEmoji" |
"/api/setting/setEntryVisibility" |
"/api/setting/setExport" |
@@ -590,13 +632,9 @@ export type APILegacyPOSTPath =
"/api/sync/setSyncProviderS3" |
"/api/sync/setSyncProviderWebDAV" |
"/api/system/addCustomEmoji" |
- "/api/system/addMicrosoftDefenderExclusion" |
- "/api/system/bootProgress" |
"/api/system/checkUpdate" |
"/api/system/checkWorkspaceDir" |
- "/api/system/clearTempFiles" |
"/api/system/createWorkspaceDir" |
- "/api/system/currentTime" |
"/api/system/dismissOnboarding" |
"/api/system/ensureOnboarding" |
"/api/system/exit" |
@@ -609,11 +647,8 @@ export type APILegacyPOSTPath =
"/api/system/getCustomFonts" |
"/api/system/getEmojiConf" |
"/api/system/getMobileWorkspaces" |
- "/api/system/getNetwork" |
"/api/system/getSysFonts" |
- "/api/system/getWorkspaceInfo" |
"/api/system/getWorkspaces" |
- "/api/system/ignoreAddMicrosoftDefenderExclusion" |
"/api/system/importConf" |
"/api/system/importCustomFont" |
"/api/system/importTLSCABundle" |
@@ -626,7 +661,6 @@ export type APILegacyPOSTPath =
"/api/system/oidc/validateActivate" |
"/api/system/oidc/validateCancel" |
"/api/system/oidc/validatePoll" |
- "/api/system/rebuildDataIndex" |
"/api/system/reloadUI" |
"/api/system/removeCustomFont" |
"/api/system/removeWorkspaceDir" |
@@ -634,21 +668,10 @@ export type APILegacyPOSTPath =
"/api/system/setAPIToken" |
"/api/system/setAccessAuthCode" |
"/api/system/setAppearanceMode" |
- "/api/system/setAutoLaunch" |
- "/api/system/setDownloadInstallPkg" |
- "/api/system/setFollowSystemLockScreen" |
- "/api/system/setNetworkProxy" |
- "/api/system/setNetworkServe" |
- "/api/system/setNetworkServeTLS" |
"/api/system/setOIDC" |
"/api/system/setUILayout" |
- "/api/system/setUpdateChannel" |
"/api/system/setWorkspaceDir" |
"/api/system/uiproc" |
- "/api/system/vacuumDataIndex" |
- "/api/tag/getTag" |
- "/api/tag/removeTag" |
- "/api/tag/renameTag" |
"/api/template/docSaveAsTemplate" |
"/api/template/getDocSaveAsTemplateInfo" |
"/api/template/manage" |
@@ -669,21 +692,116 @@ export type APILegacyPOSTPath =
"/plugin/private/:name/*path";
export interface APIPOSTRoutes {
+ "/api/attr/batchGetBlockAttrs": {
+ request: BlockIDsRequestInput;
+ response: { "code": 0; "data": Record<string, Record<string, string> | null>; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/attr/batchSetBlockAttrs": {
+ request: BatchSetBlockAttrsRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
"/api/attr/getBlockAttrs": {
request: BlockIDRequestInput;
response: { "code": 0; "data": Record<string, string>; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
body: "json";
};
+ "/api/attr/getBookmarkLabels": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": Array<string> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
"/api/attr/setBlockAttrs": {
request: SetBlockAttrsRequestInput;
response: { "code": 0; "data": 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/checkBlockExist": {
+ request: BlockQueryRequestInput;
+ response: { "code": 0; "data": boolean; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/block/checkBlockFold": {
+ request: BlockQueryRequestInput;
+ response: { "code": 0; "data": BlockFoldData; "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; };
+ body: "json";
+ };
"/api/block/getBlockInfo": {
request: BlockInfoRequestInput;
response: { "code": 0; "data": BlockInfoData; "msg": string; } | { "code": -1 | 3; "data": { "closeTimeout": number; } | null | string; "msg": string; };
body: "json";
};
+ "/api/block/getBlockRelevantIDs": {
+ request: BlockQueryRequestInput;
+ response: { "code": 0; "data": BlockRelevantData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/block/getBlockSiblingID": {
+ request: BlockQueryRequestInput;
+ response: { "code": 0; "data": BlockSiblingData; "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/getDOMText": {
+ request: DOMTextRequestInput;
+ response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/block/getDocBlocksOrders": {
+ request: DocOrdersRequestInput;
+ response: { "code": 0; "data": Array<string> | 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; };
+ body: "json";
+ };
+ "/api/block/getHeadingChildrenIDs": {
+ request: BlockIDRequestInput;
+ response: { "code": 0; "data": Array<string> | null; "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/bookmark/removeBookmark": {
+ request: RemoveBookmarkRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/bookmark/renameBookmark": {
+ request: RenameBookmarkRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/clearWorkspaceHistory": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/history/reindexHistory": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
"/api/history/searchHistory": {
request: SearchHistoryRequestInput;
response: { "code": 0; "data": SearchHistoryData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
@@ -714,11 +832,131 @@ export interface APIPOSTRoutes {
response: { "code": 0; "data": SearchTagData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
body: "json";
};
+ "/api/setting/addVirtualBlockRefExclude": {
+ request: VirtualBlockRefRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/setting/addVirtualBlockRefInclude": {
+ request: VirtualBlockRefRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/setting/getPandocBin": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/setting/refreshVirtualBlockRef": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/setting/setEditorReadOnly": {
+ request: EditorReadOnlyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/addMicrosoftDefenderExclusion": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/bootProgress": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": BootProgressData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/clearTempFiles": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/currentTime": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": number; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/getNetwork": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": NetworkData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/getWorkspaceInfo": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": WorkspaceInfoData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/ignoreAddMicrosoftDefenderExclusion": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/rebuildDataIndex": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
+ "/api/system/setAutoLaunch": {
+ request: AutoLaunchRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/setDownloadInstallPkg": {
+ request: DownloadInstallPkgRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/setFollowSystemLockScreen": {
+ request: LockScreenRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/setNetworkProxy": {
+ request: NetworkProxyInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/setNetworkServe": {
+ request: NetworkServeRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/setNetworkServeTLS": {
+ request: NetworkServeTLSRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/setUpdateChannel": {
+ request: UpdateChannelRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/system/vacuumDataIndex": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
"/api/system/version": {
request: EmptyRequestInput;
response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
body: "none";
};
+ "/api/tag/getTag": {
+ request: GetTagRequestInput;
+ response: { "code": 0; "data": Array<TagData | null> | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/tag/removeTag": {
+ request: RemoveTagRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/tag/renameTag": {
+ request: RenameTagRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
}
// 传输层合成的错误独立于业务错误;普通回调只接收消息处理后保留的非负错误码。
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index f21186cd10..d649def3e3 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -1072,12 +1072,12 @@ interface IFileTreeList {
}
interface IBlockTree {
- box: string,
+ box?: string,
revision?: string,
number?: string,
- nodeType: string,
- hPath: string,
- subType: string,
+ nodeType?: string,
+ hPath?: string,
+ subType?: string,
name: string,
type: string,
depth: number,
diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.ts
index ddfae9074b..1b6ab12b71 100644
--- a/app/src/util/backForward.ts
+++ b/app/src/util/backForward.ts
@@ -25,7 +25,7 @@ const focusStack = async (app: App, stack: IBackStack) => {
let blockElement: HTMLElement;
if (!document.contains(stack.protyle.element)) {
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.protyle.block.rootID});
- if (!response.data) {
+ if (response.code !== 0 || !response.data) {
// 页签删除
return false;
}
@@ -170,7 +170,7 @@ const focusStack = async (app: App, stack: IBackStack) => {
}
if (stack.protyle.element.parentElement) {
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.id});
- if (!response.data) {
+ if (response.code !== 0 || !response.data) {
// 块被删除
if (getSelection().rangeCount > 0) {
focusByRange(getSelection().getRangeAt(0));
diff --git a/app/tests/api-contract.types.ts b/app/tests/api-contract.types.ts
index a571b8921d..58a4491e6c 100644
--- a/app/tests/api-contract.types.ts
+++ b/app/tests/api-contract.types.ts
@@ -12,6 +12,21 @@ fetchPost("/api/attr/setBlockAttrs", {id: "id", attrs: {"custom-value": null}});
fetchPost("/api/history/searchHistory", {page: 1.5, type: null});
fetchPost(dynamicURL, {legacy: true});
fetchPost("/api/system/currentTime", {});
+fetchPost("/api/attr/batchSetBlockAttrs", {blockAttrs: [{id: "id", attrs: {remove: null}}]});
+fetchPost("/api/tag/getTag", {sort: 1.5, app: null});
+fetchPost("/api/block/getHeadingChildrenDOM", {id: "id", removeFoldAttr: null});
+fetchPost("/api/system/setAutoLaunch", {autoLaunch: 1.5});
+
+// @ts-expect-error 批量请求中的嵌套属性对象不可缺省。
+fetchPost("/api/attr/batchSetBlockAttrs", {blockAttrs: [{id: "id"}]});
+// @ts-expect-error 字符串数组不接受 null 元素。
+fetchPost("/api/attr/batchGetBlockAttrs", {ids: [null]});
+// @ts-expect-error 标签响应没有文档路径。
+fetchPost("/api/tag/getTag", {}, response => { void response.data?.[0]?.hPath; });
+// @ts-expect-error 自动启动参数必须是数字。
+fetchPost("/api/system/setAutoLaunch", {autoLaunch: "1"});
+// @ts-expect-error POST 查询不能通过 GET 调用。
+fetchGet("/api/block/getBlockSiblingID", () => {});
// @ts-expect-error 路径拼写错误不能被误认为存量接口。
fetchPost("/api/attr/getBlockAtrrs", {id: "id"});
diff --git a/docs/API-CONTRACTS.md b/docs/API-CONTRACTS.md
index 287477cc09..97237c262f 100644
--- a/docs/API-CONTRACTS.md
+++ b/docs/API-CONTRACTS.md
@@ -2,6 +2,8 @@
首批覆盖 `/api/system/version`、`/api/attr/getBlockAttrs`、`/api/attr/setBlockAttrs`、`/api/search/searchTag`、`/api/notebook/lsNotebooks`、`/api/history/searchHistory` 和 `/api/block/getBlockInfo`。版本接口同时支持 GET 和 POST,因此共登记 8 个方法与路径组合。
+截至本次迁移,契约覆盖 53 个接口、55 个方法与路径组合,存量清单仍有 572 条路由记录。后续已覆盖的范围包括快照创建与备注、系统基础查询和部分设置、属性批量读写、标签查询与标签/书签改名删除、部分编辑器设置,以及块位置、折叠状态和标题子节点查询。完整名单以 `kernel/apicontract/contracts.go` 为准;剩余工作以 `legacy_routes.json` 为准,全量迁移尚未完成。
+
## 契约与实现
`kernel/apicontract/contracts.go` 定义请求、响应和端点。契约包独立于内核启动、数据库和持久化模型,生成器可以单独运行。API 入口通过 `contractHandler` 绑定端点,请求参数和成功返回值受到 Go 泛型签名约束;响应载荷通过构造函数设置,不能直接给通用 `ret.Data` 赋值。业务校验继续使用现有辅助函数,`contractFailure` 保留其错误码、消息和已支持的错误载荷。
@@ -10,6 +12,8 @@
输入和输出分别处理。`json` tag 控制线协议字段名;请求字段默认必填,`api:"optional"` 表示可缺省,`nullable` 表示接受 `null`,指针保留可空语义。输出字段的 `omitempty` 只控制输出省略,不推导请求必填性。嵌入结构体展平,递归类型通过引用表示;接口联合、常量字段和自定义编解码需要显式建模。未支持的类型、字段冲突和未知 JSON tag 会使生成失败,不会降级为 `any`。
+数组、字典和嵌套结构体递归检查请求约束,字符串数组中的 `null` 不会被转换为空字符串,批量属性中的 `null` 值仍表示删除属性。标签树单独定义递归传输结构;前端共享树节点中的笔记本和文档路径字段为可选,反映标签节点不返回这些字段的实际行为。
+
`Notebook` 是接口载荷,业务模型通过显式转换映射到该载荷,回归测试比较完整 JSON,包括各个加密状态。修改契约不会改变 `.sy`、数据库、历史、同步或加密格式。
## 保留的兼容行为
@@ -28,6 +32,8 @@
只读中间件仍可返回带 `closeTimeout` 的提示对象。`fetchPost` 的普通回调只接收消息处理后保留的非负错误码,块信息接口的 `3` 仍须处理;`fetchSyncPost` 和 `fetchGet` 保留完整响应。动态 URL 保留存量签名;静态 POST 路径必须来自契约或存量路由,错误参数不能通过重载回退。拼接出开放范围的模板 URL 时使用显式 `string` 变量。
+业务错误需要保留提示显示时长时使用 `FailureWithTimeout`。块查询迁移后通过 `holdContractBlockRequest` 保留显式笔记本及附带 ID 的租约检查;状态查询允许已删除 ID 的行为仍由对应入口明确指定。
+
## 新增与迁移
1. 在契约包中定义传输类型与端点,并明确请求体、错误码、空值、默认值和历史输入兼容规则
@@ -56,7 +62,7 @@ pnpm exec tsx --test src/util/fetch.test.ts src/util/fetchTimeout.test.ts
```text
go test ./apicontract/...
-go test -tags "fts5 sqlcipher" ./api -run "TestAPIContract|TestBlockAttrsRespectPublishAccess|TestGetBlockInfoRecovery|TestGetBlockInfoPublishAccess|TestListNotebooksSortsBySubDocCount" -count=1
+go test -tags "fts5 sqlcipher" ./api -run "TestAPIContract|TestBlockAttrsRespectPublishAccess|TestGetBlockInfoRecovery|TestGetBlockInfoPublishAccess|TestListNotebooksSortsBySubDocCount|TestContract.*NotebookResponseLease" -count=1
```
`tsconfig.api.json` 单独启用严格检查并检查声明文件,覆盖参数错误、字段拼写、必填请求体、成功与失败分支、可空值和方法不匹配。主应用继续沿用现有配置,因此存量调用的严格空值检查并未全量开启。处理函数测试使用临时工作区和独立测试进程,不启动或重启运行中的内核。
diff --git a/docs/API.md b/docs/API.md
index 8a8bd4da8c..686ddf0d6a 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -121,7 +121,7 @@
### TypeScript contracts
-The plugin `fetchPost`, `fetchSyncPost`, and `fetchGet` declarations infer request and response types for migrated API paths from generated kernel contracts. The initial coverage includes version, block attributes, tag search, notebook listing, history search, and block information. Existing untyped endpoints and dynamic URLs remain supported. Check the response code before reading successful data from asynchronous calls, and handle nullable fields explicitly.
+The plugin `fetchPost`, `fetchSyncPost`, and `fetchGet` declarations infer request and response types for migrated API paths from generated kernel contracts. Coverage is expanding and includes system utilities, batch block attributes, tag and bookmark operations, selected block queries, notebook listing, history search, and snapshot operations. Existing untyped endpoints and dynamic URLs remain supported. Check the response code before reading successful data from asynchronous calls, and handle nullable fields explicitly.
```typescript
import {fetchSyncPost} from "siyuan";
diff --git a/docs/API.zh-CN.md b/docs/API.zh-CN.md
index 0fb2e452f4..697fa3d341 100644
--- a/docs/API.zh-CN.md
+++ b/docs/API.zh-CN.md
@@ -121,7 +121,7 @@
### TypeScript 类型契约
-插件的 `fetchPost`、`fetchSyncPost` 和 `fetchGet` 声明会根据已迁移的接口路径,从内核生成的契约推导请求与响应类型。首批覆盖版本、块属性、标签搜索、笔记本列表、历史搜索和块信息。存量未迁移接口及动态 URL 继续支持。读取异步返回值中的成功数据前须检查响应码,并显式处理可空字段。
+插件的 `fetchPost`、`fetchSyncPost` 和 `fetchGet` 声明会根据已迁移的接口路径,从内核生成的契约推导请求与响应类型。覆盖范围持续扩展,包含系统基础接口、块属性批量读写、标签及书签操作、部分块查询、笔记本列表、历史搜索和快照操作。存量未迁移接口及动态 URL 继续支持。读取异步返回值中的成功数据前须检查响应码,并显式处理可空字段。
```typescript
import {fetchSyncPost} from "siyuan";
diff --git a/kernel/api/attr.go b/kernel/api/attr.go
index 07567235f9..4e55f65d55 100644
--- a/kernel/api/attr.go
+++ b/kernel/api/attr.go
@@ -17,9 +17,6 @@
package api
import (
- "fmt"
- "net/http"
-
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/apicontract"
@@ -29,35 +26,17 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func getBookmarkLabels(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
+var getBookmarkLabels = contractHandler(apicontract.GetBookmarkLabels, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[[]string] {
if model.IsReadOnlyRoleContext(c) {
- ret.Data = model.BookmarkLabelsByPublishAccess(c, model.GetPublishAccess())
- } else {
- ret.Data = model.BookmarkLabels()
- }
-}
-
-func batchGetBlockAttrs(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- ids := arg["ids"].([]any)
- var idList []string
- for _, id := range ids {
- idList = append(idList, id.(string))
+ return apicontract.Success(model.BookmarkLabelsByPublishAccess(c, model.GetPublishAccess()))
}
+ return apicontract.Success(model.BookmarkLabels())
+})
- idList = filterBlockIDsByPublishAccess(c, idList, "")
- ret.Data = sql.BatchGetBlockAttrs(idList)
-}
+var batchGetBlockAttrs = contractHandler(apicontract.BatchGetBlockAttrs, func(c *gin.Context, request apicontract.BlockIDsRequest) apicontract.Response[map[string]map[string]string] {
+ ids := filterBlockIDsByPublishAccess(c, request.IDs, "")
+ return apicontract.Success(sql.BatchGetBlockAttrs(ids))
+})
var getBlockAttrs = contractHandler(apicontract.GetBlockAttrs, func(c *gin.Context, request apicontract.BlockIDRequest) apicontract.Response[map[string]string] {
ret := gulu.Ret.NewResult()
@@ -108,50 +87,24 @@ var setBlockAttrs = contractHandler(apicontract.SetBlockAttrs, func(c *gin.Conte
return apicontract.Success(apicontract.Null{})
})
-func batchSetBlockAttrs(c *gin.Context) {
+var batchSetBlockAttrs = contractHandler(apicontract.BatchSetBlockAttrs, func(c *gin.Context, request apicontract.BatchSetBlockAttrsRequest) apicontract.Response[apicontract.Null] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- blockAttrsArg := arg["blockAttrs"].([]any)
var blockAttrs []map[string]any
- for _, blockAttrArg := range blockAttrsArg {
- blockAttr := blockAttrArg.(map[string]any)
- id := blockAttr["id"].(string)
- if util.InvalidIDPattern(id, ret) {
- return
+ for _, block := range request.BlockAttrs {
+ if util.InvalidIDPattern(block.ID, ret) {
+ return contractFailure[apicontract.Null](ret)
}
-
- attrs := blockAttr["attrs"].(map[string]any)
- nameValues := map[string]string{}
- for name, value := range attrs {
- if nil == value {
- nameValues[name] = ""
- } else {
- strValue, ok := value.(string)
- if !ok {
- ret.Code = -1
- ret.Msg = fmt.Sprintf("the value of attr [%s] must be a string", name)
- return
- }
- nameValues[name] = strValue
+ attrs := map[string]string{}
+ for name, value := range block.Attrs {
+ attrs[name] = ""
+ if value != nil {
+ attrs[name] = *value
}
}
-
- blockAttrs = append(blockAttrs, map[string]any{
- "id": id,
- "attrs": nameValues,
- })
+ blockAttrs = append(blockAttrs, map[string]any{"id": block.ID, "attrs": attrs})
}
-
- err := model.BatchSetBlockAttrs(blockAttrs)
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ if err := model.BatchSetBlockAttrs(blockAttrs); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
diff --git a/kernel/api/block.go b/kernel/api/block.go
index 21b4af3c89..5b9df70235 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -228,74 +228,32 @@ func getBlockTreeInfos(c *gin.Context) {
ret.Data = model.GetBlockTreeInfosInBox(ids, boxID)
}
-func getBlockSiblingID(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)
- boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg) {
- return
- }
- if !isBlockPublishAccessible(c, id, boxID) {
- ret.Data = map[string]string{
- "parent": "",
- "next": "",
- "previous": "",
- }
- return
- }
-
- parent, previous, next := model.GetBlockSiblingIDInBox(id, boxID)
- ret.Data = map[string]string{
- "parent": parent,
- "next": next,
- "previous": previous,
+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)
+ if err != nil {
+ return apicontract.Failure[apicontract.BlockSiblingData](-1, err.Error())
}
-}
-
-func getBlockRelevantIDs(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if !isBlockPublishAccessible(c, request.ID, boxID) {
+ return apicontract.Success(apicontract.BlockSiblingData{})
}
+ parent, previous, next := model.GetBlockSiblingIDInBox(request.ID, boxID)
+ return apicontract.Success(apicontract.BlockSiblingData{Parent: parent, Previous: previous, Next: next})
+})
- id := arg["id"].(string)
- boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg) {
- return
- }
- if !isBlockPublishAccessible(c, id, boxID) {
- ret.Data = map[string]string{
- "parentID": "",
- "previousID": "",
- "nextID": "",
- }
- return
+var getBlockRelevantIDs = contractHandler(apicontract.GetBlockRelevantIDs, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.BlockRelevantData] {
+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)
+ if err != nil {
+ return apicontract.Failure[apicontract.BlockRelevantData](-1, err.Error())
}
-
- parentID, previousID, nextID, err := model.GetBlockRelevantIDsInBox(id, boxID)
- if nil != err {
- ret.Code = -1
- ret.Msg = err.Error()
- ret.Data = map[string]any{"closeTimeout": 7000}
- return
+ if !isBlockPublishAccessible(c, request.ID, boxID) {
+ return apicontract.Success(apicontract.BlockRelevantData{})
}
-
- ret.Data = map[string]string{
- "parentID": parentID,
- "previousID": previousID,
- "nextID": nextID,
+ parent, previous, next, err := model.GetBlockRelevantIDsInBox(request.ID, boxID)
+ if err != nil {
+ return apicontract.FailureWithTimeout[apicontract.BlockRelevantData](-1, err.Error(), 7000)
}
-}
+ return apicontract.Success(apicontract.BlockRelevantData{ParentID: parent, PreviousID: previous, NextID: next})
+})
func transferBlockRef(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -361,59 +319,30 @@ func swapBlockRef(c *gin.Context) {
}
}
-func getHeadingChildrenIDs(c *gin.Context) {
+var getHeadingChildrenIDs = contractHandler(apicontract.GetHeadingChildrenIDs, func(c *gin.Context, request apicontract.BlockIDRequest) 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)
- if !checkBlockPublishAccess(c, id, ret) {
- return
- }
-
- ids := model.GetHeadingChildrenIDs(id)
- ret.Data = ids
-}
-
-func appendHeadingChildren(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if !checkBlockPublishAccess(c, request.ID, ret) {
+ return contractFailure[[]string](ret)
}
+ return apicontract.Success(model.GetHeadingChildrenIDs(request.ID))
+})
- id := arg["id"].(string)
- childrenDOM := arg["childrenDOM"].(string)
- model.AppendHeadingChildren(id, childrenDOM)
-}
+var appendHeadingChildren = contractHandler(apicontract.AppendHeadingChildren, func(c *gin.Context, request apicontract.AppendHeadingChildrenRequest) apicontract.Response[apicontract.Null] {
+ model.AppendHeadingChildren(request.ID, request.ChildrenDOM)
+ return apicontract.Success(apicontract.Null{})
+})
-func getHeadingChildrenDOM(c *gin.Context) {
+var getHeadingChildrenDOM = contractHandler(apicontract.GetHeadingChildrenDOM, func(c *gin.Context, request apicontract.HeadingChildrenRequest) apicontract.Response[string] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if !checkBlockPublishAccess(c, request.ID, ret) {
+ return contractFailure[string](ret)
}
-
- id := arg["id"].(string)
- if !checkBlockPublishAccess(c, id, ret) {
- return
- }
-
removeFoldAttr := true
- if nil != arg["removeFoldAttr"] {
- removeFoldAttr = arg["removeFoldAttr"].(bool)
+ if request.RemoveFoldAttr != nil {
+ removeFoldAttr = *request.RemoveFoldAttr
}
- dom := model.GetHeadingChildrenDOM(id, removeFoldAttr)
- ret.Data = dom
-}
+ return apicontract.Success(model.GetHeadingChildrenDOM(request.ID, removeFoldAttr))
+})
func getHeadingDeleteTransaction(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -580,80 +509,39 @@ func setCloudReminder(c *gin.Context) {
}
}
-func getUnfoldedParentID(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)
- boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg) {
- return
- }
- if !isBlockPublishAccessible(c, id, boxID) {
- ret.Data = map[string]any{
- "parentID": "",
- }
- return
- }
- parentID := model.GetUnfoldedParentID(id)
- ret.Data = map[string]any{
- "parentID": parentID,
+var getUnfoldedParentID = contractHandler(apicontract.GetUnfoldedParentID, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.UnfoldedParentData] {
+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)
+ if err != nil {
+ return apicontract.Failure[apicontract.UnfoldedParentData](-1, err.Error())
}
-}
-
-func checkBlockFold(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if !isBlockPublishAccessible(c, request.ID, boxID) {
+ return apicontract.Success(apicontract.UnfoldedParentData{})
}
+ return apicontract.Success(apicontract.UnfoldedParentData{ParentID: model.GetUnfoldedParentID(request.ID)})
+})
- id := arg["id"].(string)
- boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg, true) {
- return
- }
- if !isBlockPublishAccessible(c, id, boxID) {
- ret.Data = map[string]any{
- "isFolded": false,
- "isRoot": false,
- }
- return
- }
- isFolded, isRoot := model.IsBlockFolded(id)
- ret.Data = map[string]any{
- "isFolded": isFolded,
- "isRoot": isRoot,
+var checkBlockFold = contractHandler(apicontract.CheckBlockFold, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[apicontract.BlockFoldData] {
+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, true)
+ if err != nil {
+ return apicontract.Failure[apicontract.BlockFoldData](-1, err.Error())
}
-}
-
-func checkBlockExist(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if !isBlockPublishAccessible(c, request.ID, boxID) {
+ return apicontract.Success(apicontract.BlockFoldData{})
}
+ isFolded, isRoot := model.IsBlockFolded(request.ID)
+ return apicontract.Success(apicontract.BlockFoldData{IsFolded: isFolded, IsRoot: isRoot})
+})
- id := arg["id"].(string)
- boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg, true) {
- return
+var checkBlockExist = contractHandler(apicontract.CheckBlockExist, func(c *gin.Context, request apicontract.BlockQueryRequest) apicontract.Response[bool] {
+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, true)
+ if err != nil {
+ return apicontract.Failure[bool](-1, err.Error())
}
- if !isBlockPublishAccessible(c, id, boxID) {
- ret.Data = false
- return
+ if !isBlockPublishAccessible(c, request.ID, boxID) {
+ return apicontract.Success(false)
}
- ret.Data = treenode.ExistBlockTree(id)
-}
+ return apicontract.Success(treenode.ExistBlockTree(request.ID))
+})
func checkBlocksExist(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -870,18 +758,9 @@ func getTreeStat(c *gin.Context) {
ret.Data = data
}
-func getDOMText(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- dom := arg["dom"].(string)
- ret.Data = model.GetDOMText(dom)
-}
+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) {
ret := gulu.Ret.NewResult()
@@ -1111,76 +990,37 @@ func getBlockBreadcrumbChildren(c *gin.Context) {
ret.Data = children
}
-func getBlockIndex(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)
- boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg, true) {
- return
- }
- if !isBlockPublishAccessible(c, id, boxID) {
- ret.Data = 0
- return
+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)
+ if err != nil {
+ return apicontract.Failure[int](-1, err.Error())
}
- index := model.GetBlockIndex(id)
- ret.Data = index
-}
-
-func getBlocksIndexes(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if !isBlockPublishAccessible(c, request.ID, boxID) {
+ return apicontract.Success(0)
}
+ return apicontract.Success(model.GetBlockIndex(request.ID))
+})
- 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) {
- return
+var getBlocksIndexes = contractHandler(apicontract.GetBlocksIndexes, func(c *gin.Context, request apicontract.BlocksQueryRequest) apicontract.Response[map[string]int] {
+ boxID, err := holdContractBlockRequest(c, request.Notebook, request.ID, request.IDs, false)
+ if err != nil {
+ return apicontract.Failure[map[string]int](-1, err.Error())
}
- ids = filterBlockIDsByPublishAccess(c, ids, boxID)
- index := model.GetBlocksIndexes(ids)
- ret.Data = index
-}
+ ids := filterBlockIDsByPublishAccess(c, request.IDs, boxID)
+ return apicontract.Success(model.GetBlocksIndexes(ids))
+})
-func getDocBlocksOrders(c *gin.Context) {
+var getDocBlocksOrders = contractHandler(apicontract.GetDocBlocksOrders, func(c *gin.Context, request apicontract.DocOrdersRequest) apicontract.Response[[]string] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if util.InvalidIDPattern(request.ID, ret) || !checkBlockPublishAccess(c, request.ID, ret) {
+ return contractFailure[[]string](ret)
}
-
- var id string
- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) || util.InvalidIDPattern(id, ret) {
- return
- }
- if !checkBlockPublishAccess(c, id, ret) {
- return
- }
-
- orders, err := model.GetDocBlocksOrders(id)
+ orders, err := model.GetDocBlocksOrders(request.ID)
if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ return apicontract.Failure[[]string](-1, err.Error())
}
- ret.Data = orders
-}
+ return apicontract.Success(orders)
+})
var getBlockInfo = contractHandler(apicontract.GetBlockInfo, func(c *gin.Context, request apicontract.BlockInfoRequest) apicontract.Response[apicontract.BlockInfoData] {
ret := gulu.Ret.NewResult()
diff --git a/kernel/api/bookmark.go b/kernel/api/bookmark.go
index 21b3faeeb7..ea9dc43a78 100644
--- a/kernel/api/bookmark.go
+++ b/kernel/api/bookmark.go
@@ -21,8 +21,8 @@ import (
"github.com/88250/gulu"
"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 getBookmark(c *gin.Context) {
@@ -45,47 +45,16 @@ func getBookmark(c *gin.Context) {
ret.Data = bookmarks
}
-func removeBookmark(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var bookmark string
- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("bookmark", &bookmark, true, false)) {
- return
- }
- if err := model.RemoveBookmark(bookmark); err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- ret.Data = map[string]any{"closeTimeout": 5000}
- return
- }
-}
-
-func renameBookmark(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+var removeBookmark = contractHandler(apicontract.RemoveBookmark, func(c *gin.Context, request apicontract.RemoveBookmarkRequest) apicontract.Response[apicontract.Null] {
+ if err := model.RemoveBookmark(request.Bookmark); err != nil {
+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 5000)
}
+ return apicontract.Success(apicontract.Null{})
+})
- var oldBookmark, newBookmark string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("oldBookmark", &oldBookmark, true, false),
- util.BindJsonArg("newBookmark", &newBookmark, true, false),
- ) {
- return
- }
- if err := model.RenameBookmark(oldBookmark, newBookmark); err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- ret.Data = map[string]any{"closeTimeout": 5000}
- return
+var renameBookmark = contractHandler(apicontract.RenameBookmark, func(c *gin.Context, request apicontract.RenameBookmarkRequest) apicontract.Response[apicontract.Null] {
+ if err := model.RenameBookmark(request.OldBookmark, request.NewBookmark); err != nil {
+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 5000)
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
diff --git a/kernel/api/box_lease_test.go b/kernel/api/box_lease_test.go
index e26e110fef..d18045c3ea 100644
--- a/kernel/api/box_lease_test.go
+++ b/kernel/api/box_lease_test.go
@@ -69,6 +69,14 @@ func TestGetBlockInfoNotebookResponseLease(t *testing.T) {
runNotebookResponseLease(t, false, false)
}
+func TestContractSiblingNotebookResponseLease(t *testing.T) {
+ runNotebookResponseLease(t, false, false)
+}
+
+func TestContractBatchIndexesNotebookResponseLease(t *testing.T) {
+ runNotebookResponseLease(t, false, true)
+}
+
func runNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {
t.Helper()
if os.Getenv("SIYUAN_TEST_NOTEBOOK_RESPONSE_LEASE") == t.Name() {
@@ -147,6 +155,8 @@ func testNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {
engine.POST("/api/block/getBlockKramdown", getBlockKramdown)
engine.POST("/api/block/getBlockKramdowns", getBlockKramdowns)
engine.POST("/api/block/getBlockInfo", getBlockInfo)
+ engine.POST("/api/block/getBlockSiblingID", getBlockSiblingID)
+ engine.POST("/api/block/getBlocksIndexes", getBlocksIndexes)
writer := &blockedBlockResponseWriter{ResponseRecorder: httptest.NewRecorder(), ready: make(chan []byte, 1), proceed: make(chan struct{})}
var releaseWriter sync.Once
defer releaseWriter.Do(func() { close(writer.proceed) })
@@ -163,6 +173,13 @@ func testNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {
args["ids"] = boxIDs
endpoint += "s"
}
+ typedQuery := false
+ switch t.Name() {
+ case "TestContractSiblingNotebookResponseLease":
+ endpoint, typedQuery = "/api/block/getBlockSiblingID", true
+ case "TestContractBatchIndexesNotebookResponseLease":
+ endpoint, typedQuery = "/api/block/getBlocksIndexes", true
+ }
requestBody, err := json.Marshal(args)
if err != nil {
t.Fatal(err)
@@ -177,7 +194,7 @@ func testNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {
case <-time.After(5 * time.Second):
t.Fatal("response never reached writer")
}
- if strings.Count(string(body), "REVIEW-SECRET-CONTENT") != count {
+ if !typedQuery && strings.Count(string(body), "REVIEW-SECRET-CONTENT") != count {
releaseWriter.Do(func() { close(writer.proceed) })
<-responseDone
t.Fatalf("fixture did not produce plaintext: %s", body)
@@ -194,6 +211,15 @@ func testNotebookResponseLease(t *testing.T, explicitNotebook, batch bool) {
}
releaseWriter.Do(func() { close(writer.proceed) })
<-responseDone
+ if typedQuery {
+ requireAPIContract(t, http.MethodPost, endpoint, writer.ResponseRecorder)
+ var response struct {
+ Code int `json:"code"`
+ }
+ if err := json.Unmarshal(body, &response); err != nil || response.Code != 0 {
+ t.Fatalf("typed query failed: %s, %v", body, err)
+ }
+ }
remaining := len(boxIDs)
if lockedBeforeResponse {
remaining--
diff --git a/kernel/api/contract.go b/kernel/api/contract.go
index b772144590..be725fad16 100644
--- a/kernel/api/contract.go
+++ b/kernel/api/contract.go
@@ -46,3 +46,13 @@ func notebookContract(box *model.Box) *apicontract.Notebook {
Encrypted: box.Encrypted, Unlocked: box.Unlocked, State: string(box.State),
}
}
+
+// holdContractBlockRequest 保留显式笔记本选择及全部附带 ID 的租约检查。
+func holdContractBlockRequest(c *gin.Context, notebook, id string, ids []string, allowMissing bool) (boxID string, err error) {
+ if notebook != "" && model.IsEncryptedBox(notebook) {
+ boxID = notebook
+ }
+ leaseIDs := append([]string{id}, ids...)
+ err = holdEncryptedBlockRequests(c, boxID, leaseIDs, allowMissing)
+ return
+}
diff --git a/kernel/api/contract_basics_test.go b/kernel/api/contract_basics_test.go
new file mode 100644
index 0000000000..00be630cbd
--- /dev/null
+++ b/kernel/api/contract_basics_test.go
@@ -0,0 +1,69 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/model"
+)
+
+func TestAPIContractBasicRequests(t *testing.T) {
+ gin.SetMode(gin.TestMode)
+ for _, entry := range []struct {
+ path, body string
+ handler gin.HandlerFunc
+ code int
+ }{
+ {"/api/system/currentTime", "", currentTime, 0},
+ {"/api/system/bootProgress", "", bootProgress, 0},
+ {"/api/system/getWorkspaceInfo", "", getWorkspaceInfo, 0},
+ {"/api/block/getDOMText", `{"dom":null}`, getDOMText, -1},
+ {"/api/system/setAutoLaunch", `{"autoLaunch":"1"}`, setAutoLaunch, -1},
+ {"/api/system/setFollowSystemLockScreen", `{}`, setFollowSystemLockScreen, -1},
+ {"/api/system/setNetworkServe", `{"networkServe":null}`, setNetworkServe, -1},
+ {"/api/system/setNetworkServeTLS", `{"networkServeTLS":1}`, setNetworkServeTLS, -1},
+ {"/api/system/setNetworkProxy", `{"scheme":"http","host":"host"}`, setNetworkProxy, -1},
+ {"/api/system/setDownloadInstallPkg", `{"downloadInstallPkg":"true"}`, setDownloadInstallPkg, -1},
+ {"/api/system/setUpdateChannel", `{"updateChannel":null}`, setUpdateChannel, -1},
+ {"/api/setting/setEditorReadOnly", `{"readonly":1}`, setEditorReadOnly, -1},
+ {"/api/setting/addVirtualBlockRefInclude", `{"keywords":[null]}`, addVirtualBlockRefInclude, -1},
+ {"/api/setting/addVirtualBlockRefExclude", `{"keywords":1}`, addVirtualBlockRefExclude, -1},
+ {"/api/attr/batchGetBlockAttrs", `{"ids":[null]}`, batchGetBlockAttrs, -1},
+ {"/api/attr/batchSetBlockAttrs", `{"blockAttrs":[{}]}`, batchSetBlockAttrs, -1},
+ {"/api/bookmark/removeBookmark", `{}`, removeBookmark, -1},
+ {"/api/bookmark/renameBookmark", `{"oldBookmark":"a"}`, renameBookmark, -1},
+ {"/api/tag/getTag", `{"sort":"1"}`, getTag, -1},
+ {"/api/tag/removeTag", `{"label":null}`, removeTag, -1},
+ {"/api/tag/renameTag", `{"oldLabel":"a","newLabel":" "}`, renameTag, -1},
+ } {
+ t.Run(entry.path, func(t *testing.T) {
+ engine := gin.New()
+ engine.POST(entry.path, entry.handler)
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", entry.path, strings.NewReader(entry.body)))
+ requireAPIContract(t, "POST", entry.path, recorder)
+ var response struct {
+ Code int `json:"code"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != entry.code {
+ t.Fatalf("unexpected response: %s, %v", recorder.Body.String(), err)
+ }
+ })
+ }
+}
+
+func TestAPIContractTagConversion(t *testing.T) {
+ for _, tags := range []model.Tags{nil, {}, {nil}, {&model.Tag{Name: "root", Label: "Root", Type: "tag", Depth: 1, Count: 2, Children: model.Tags{&model.Tag{Name: "child", Children: model.Tags{}}}}}} {
+ before, err := json.Marshal(tags)
+ if err != nil {
+ t.Fatal(err)
+ }
+ after, err := json.Marshal(tagContracts(tags))
+ if err != nil || string(before) != string(after) {
+ t.Fatalf("tag JSON changed: %s != %s, %v", before, after, err)
+ }
+ }
+}
diff --git a/kernel/api/contract_test.go b/kernel/api/contract_test.go
index ee1e3f8485..656d92f726 100644
--- a/kernel/api/contract_test.go
+++ b/kernel/api/contract_test.go
@@ -162,6 +162,24 @@ func TestAPIContractHandlers(t *testing.T) {
return response
}
admin := model.RoleAdministrator
+ blockQueries := []struct {
+ path string
+ handler gin.HandlerFunc
+ }{
+ {"/api/block/getBlockSiblingID", getBlockSiblingID},
+ {"/api/block/getBlockRelevantIDs", getBlockRelevantIDs},
+ {"/api/block/getUnfoldedParentID", getUnfoldedParentID},
+ {"/api/block/checkBlockFold", checkBlockFold},
+ {"/api/block/checkBlockExist", checkBlockExist},
+ {"/api/block/getBlockIndex", getBlockIndex},
+ {"/api/block/getDocBlocksOrders", getDocBlocksOrders},
+ {"/api/block/getHeadingChildrenIDs", getHeadingChildrenIDs},
+ {"/api/block/getHeadingChildrenDOM", getHeadingChildrenDOM},
+ }
+ domText := request("POST", "/api/block/getDOMText", `{"dom":"<div>text</div>"}`, admin, getDOMText)
+ if domText["code"] != float64(0) || domText["data"] != model.GetDOMText("<div>text</div>") {
+ t.Fatalf("DOM text response changed: %+v", domText)
+ }
for _, method := range []string{"GET", "POST"} {
response := request(method, "/api/system/version", "", admin, version)
if response["data"] != util.Ver {
@@ -172,6 +190,16 @@ func TestAPIContractHandlers(t *testing.T) {
if info["code"] != float64(0) || info["data"].(map[string]any)["rootID"] != docID {
t.Fatalf("block info failed: %+v", info)
}
+ for _, entry := range blockQueries {
+ response := request("POST", entry.path, `{"id":"`+docID+`"}`, admin, entry.handler)
+ if response["code"] != float64(0) {
+ t.Fatalf("block query failed for %s: %+v", entry.path, response)
+ }
+ }
+ indexes := request("POST", "/api/block/getBlocksIndexes", `{"ids":["`+docID+`"]}`, admin, getBlocksIndexes)
+ if indexes["code"] != float64(0) {
+ t.Fatalf("batch indexes failed: %+v", indexes)
+ }
attrs := request("POST", "/api/attr/getBlockAttrs", `{"id":"`+docID+`"}`, admin, getBlockAttrs)
if attrs["data"].(map[string]any)["custom-value"] != "before" {
t.Fatal("attribute fixture was not read")
@@ -188,6 +216,19 @@ func TestAPIContractHandlers(t *testing.T) {
if values["custom-other"] != "after" {
t.Fatal("attribute update was not preserved")
}
+ batch := request("POST", "/api/attr/batchGetBlockAttrs", `{"ids":["`+docID+`"]}`, admin, batchGetBlockAttrs)
+ if batch["data"].(map[string]any)[docID].(map[string]any)["custom-other"] != "after" {
+ t.Fatalf("batch attribute lookup changed: %+v", batch)
+ }
+ batch = request("POST", "/api/attr/batchSetBlockAttrs", `{"blockAttrs":[{"id":"`+docID+`","attrs":{"custom-other":null,"custom-batch":"value"}}]}`, admin, batchSetBlockAttrs)
+ if batch["code"] != float64(0) || batch["data"] != nil {
+ t.Fatalf("batch update failed: %+v", batch)
+ }
+ batch = request("POST", "/api/attr/batchGetBlockAttrs", `{"ids":["`+docID+`"]}`, admin, batchGetBlockAttrs)
+ batchAttrs := batch["data"].(map[string]any)[docID].(map[string]any)
+ if _, exists := batchAttrs["custom-other"]; exists || batchAttrs["custom-batch"] != "value" {
+ t.Fatalf("batch attribute deletion changed: %+v", batchAttrs)
+ }
tags := request("POST", "/api/search/searchTag", `{"k":""}`, admin, searchTag)
if !reflect.DeepEqual(tags["data"].(map[string]any)["tags"], []any{}) {
t.Fatalf("empty tag response changed: %+v", tags)
@@ -239,5 +280,15 @@ func TestAPIContractHandlers(t *testing.T) {
if !visible && data["rootTitle"] != "" {
t.Fatal("private document title was exposed")
}
+ for _, entry := range blockQueries {
+ response := request("POST", entry.path, `{"id":"`+docID+`"}`, model.RoleReader, entry.handler)
+ if fields, ok := response["data"].(map[string]any); ok {
+ for key, value := range fields {
+ if value != "" && value != false {
+ t.Fatalf("protected block metadata exposed by %s: %s=%v", entry.path, key, value)
+ }
+ }
+ }
+ }
}
}
diff --git a/kernel/api/history.go b/kernel/api/history.go
index 55fb8a3fec..4cf033214d 100644
--- a/kernel/api/history.go
+++ b/kernel/api/history.go
@@ -74,12 +74,10 @@ func getHistoryItems(c *gin.Context) {
}
}
-func reindexHistory(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
+var reindexHistory = contractHandler(apicontract.ReindexHistory, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
model.ReindexHistory()
-}
+ return apicontract.Success(apicontract.Null{})
+})
func getNotebookHistory(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -97,20 +95,15 @@ func getNotebookHistory(c *gin.Context) {
}
}
-func clearWorkspaceHistory(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- msgId := util.PushMsg(model.Conf.Language(100), 1000*60*15)
+var clearWorkspaceHistory = contractHandler(apicontract.ClearWorkspaceHistory, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
+ msgID := util.PushMsg(model.Conf.Language(100), 1000*60*15)
time.Sleep(3 * time.Second)
- err := model.ClearWorkspaceHistory()
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ if err := model.ClearWorkspaceHistory(); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
- util.PushUpdateMsg(msgId, model.Conf.Language(99), 1000*5)
-}
+ util.PushUpdateMsg(msgID, model.Conf.Language(99), 1000*5)
+ return apicontract.Success(apicontract.Null{})
+})
func getDocHistoryContent(c *gin.Context) {
ret := gulu.Ret.NewResult()
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index eba67d6578..bf22e6cdef 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -26,6 +26,7 @@ import (
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/logging"
+ "github.com/siyuan-note/siyuan/kernel/apicontract"
"github.com/siyuan-note/siyuan/kernel/conf"
mcpserver "github.com/siyuan-note/siyuan/kernel/mcp"
mcpclient "github.com/siyuan-note/siyuan/kernel/mcp/client"
@@ -41,25 +42,16 @@ var (
bazaarPetalStateRevision uint64
)
-func setEditorReadOnly(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
- readOnly := arg["readonly"].(bool)
-
+var setEditorReadOnly = contractHandler(apicontract.SetEditorReadOnly, func(c *gin.Context, request apicontract.EditorReadOnlyRequest) apicontract.Response[apicontract.Null] {
oldReadOnly := model.Conf.Editor.ReadOnly
- model.Conf.Editor.ReadOnly = readOnly
+ model.Conf.Editor.ReadOnly = request.ReadOnly
model.Conf.Save()
-
if oldReadOnly != model.Conf.Editor.ReadOnly {
util.BroadcastByType("protyle", "readonly", 0, "", model.Conf.Editor.ReadOnly)
util.BroadcastByType("main", "readonly", 0, "", model.Conf.Editor.ReadOnly)
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
func setConfSnippet(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -91,57 +83,23 @@ func setConfSnippet(c *gin.Context) {
model.PushReloadSnippet(snippet)
}
-func addVirtualBlockRefExclude(c *gin.Context) {
- // Add internal kernel API `/api/setting/addVirtualBlockRefExclude` https://github.com/siyuan-note/siyuan/issues/9909
-
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- keywordsArg := arg["keywords"]
- var keywords []string
- for _, k := range keywordsArg.([]any) {
- keywords = append(keywords, k.(string))
- }
-
- model.AddVirtualBlockRefExclude(keywords)
+var addVirtualBlockRefExclude = contractHandler(apicontract.AddVirtualBlockRefExclude, func(c *gin.Context, request apicontract.VirtualBlockRefRequest) apicontract.Response[apicontract.Null] {
+ model.AddVirtualBlockRefExclude(request.Keywords)
util.BroadcastByType("main", "setConf", 0, "", model.Conf)
-}
-
-func addVirtualBlockRefInclude(c *gin.Context) {
- // Add internal kernel API `/api/setting/addVirtualBlockRefInclude` https://github.com/siyuan-note/siyuan/issues/9909
+ return apicontract.Success(apicontract.Null{})
+})
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- keywordsArg := arg["keywords"]
- var keywords []string
- for _, k := range keywordsArg.([]any) {
- keywords = append(keywords, k.(string))
- }
-
- model.AddVirtualBlockRefInclude(keywords)
+var addVirtualBlockRefInclude = contractHandler(apicontract.AddVirtualBlockRefInclude, func(c *gin.Context, request apicontract.VirtualBlockRefRequest) apicontract.Response[apicontract.Null] {
+ model.AddVirtualBlockRefInclude(request.Keywords)
util.BroadcastByType("main", "setConf", 0, "", model.Conf)
-}
-
-func refreshVirtualBlockRef(c *gin.Context) {
- // Add internal kernel API `/api/setting/refreshVirtualBlockRef` https://github.com/siyuan-note/siyuan/issues/9829
-
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+ return apicontract.Success(apicontract.Null{})
+})
+var refreshVirtualBlockRef = contractHandler(apicontract.RefreshVirtualBlockRef, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
model.ResetVirtualBlockRefCache()
util.BroadcastByType("main", "setConf", 0, "", model.Conf)
-}
+ return apicontract.Success(apicontract.Null{})
+})
func setBazaar(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -571,22 +529,17 @@ func setExport(c *gin.Context) {
ret.Data = model.Conf.Export
}
-func getPandocBin(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
+var getPandocBin = contractHandler(apicontract.GetPandocBin, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[string] {
pandocRuntime := util.GetPandocRuntime()
if !util.IsValidPandocBin(pandocRuntime.BinPath) {
util.InitPandoc(model.Conf.Export.PandocBin)
pandocRuntime = util.GetPandocRuntime()
}
if !util.IsValidPandocBin(pandocRuntime.BinPath) {
- ret.Code = -1
- ret.Msg = model.Conf.Language(115)
- return
+ return apicontract.Failure[string](-1, model.Conf.Language(115))
}
- ret.Data = pandocRuntime.BinPath
-}
+ return apicontract.Success(pandocRuntime.BinPath)
+})
func setFiletree(c *gin.Context) {
ret := gulu.Ret.NewResult()
diff --git a/kernel/api/system.go b/kernel/api/system.go
index 3f54ba7c17..e2ea78f80c 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -45,79 +45,53 @@ import (
"golang.org/x/mod/semver"
)
-func clearTempFiles(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
+var clearTempFiles = contractHandler(apicontract.ClearTempFiles, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
model.ClearTempFiles()
-}
-
-func vacuumDataIndex(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+ return apicontract.Success(apicontract.Null{})
+})
+var vacuumDataIndex = contractHandler(apicontract.VacuumDataIndex, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
model.VacuumDataIndex()
-}
-
-func rebuildDataIndex(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+ return apicontract.Success(apicontract.Null{})
+})
+var rebuildDataIndex = contractHandler(apicontract.RebuildDataIndex, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
model.FullReindex(false)
-}
-
-func addMicrosoftDefenderExclusion(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- if !gulu.OS.IsWindows() {
- return
- }
-
- err := model.AddMicrosoftDefenderExclusion()
- if nil != err {
- ret.Code = -1
- ret.Msg = err.Error()
- }
-}
-
-func ignoreAddMicrosoftDefenderExclusion(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+ return apicontract.Success(apicontract.Null{})
+})
- if !gulu.OS.IsWindows() {
- return
+var addMicrosoftDefenderExclusion = contractHandler(apicontract.AddMicrosoftDefenderExclusion, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
+ if gulu.OS.IsWindows() {
+ if err := model.AddMicrosoftDefenderExclusion(); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
+ }
}
+ return apicontract.Success(apicontract.Null{})
+})
- model.Conf.System.MicrosoftDefenderExcluded = true
- model.Conf.Save()
-}
-
-func getWorkspaceInfo(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- ret.Data = map[string]any{
- "workspaceDir": util.WorkspaceDir,
- "siyuanVer": util.Ver,
+var ignoreAddMicrosoftDefenderExclusion = contractHandler(apicontract.IgnoreAddMicrosoftDefenderExclusion, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
+ if gulu.OS.IsWindows() {
+ model.Conf.System.MicrosoftDefenderExcluded = true
+ model.Conf.Save()
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
-func getNetwork(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+var getWorkspaceInfo = contractHandler(apicontract.GetWorkspaceInfo, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.WorkspaceInfoData] {
+ return apicontract.Success(apicontract.WorkspaceInfoData{WorkspaceDir: util.WorkspaceDir, SiyuanVer: util.Ver})
+})
+var getNetwork = contractHandler(apicontract.GetNetwork, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.NetworkData] {
maskedConf, err := model.GetMaskedConf()
if err != nil {
- ret.Code = -1
- ret.Msg = "get conf failed: " + err.Error()
- return
+ return apicontract.Failure[apicontract.NetworkData](-1, "get conf failed: "+err.Error())
}
-
- ret.Data = map[string]any{
- "proxy": maskedConf.System.NetworkProxy,
+ var proxy *apicontract.NetworkProxy
+ if value := maskedConf.System.NetworkProxy; value != nil {
+ proxy = &apicontract.NetworkProxy{Scheme: value.Scheme, Host: value.Host, Port: value.Port}
}
-}
+ return apicontract.Success(apicontract.NetworkData{Proxy: proxy})
+})
func getChangelog(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -1063,21 +1037,11 @@ func setOIDC(c *gin.Context) {
}
}
-func setFollowSystemLockScreen(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- lockScreenMode := int(arg["lockScreenMode"].(float64))
-
- model.Conf.System.LockScreenMode = lockScreenMode
+var setFollowSystemLockScreen = contractHandler(apicontract.SetFollowSystemLockScreen, func(c *gin.Context, request apicontract.LockScreenRequest) apicontract.Response[apicontract.Null] {
+ model.Conf.System.LockScreenMode = int(request.LockScreenMode)
model.Conf.Save()
- return
-}
+ return apicontract.Success(apicontract.Null{})
+})
func getSysFonts(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -1232,20 +1196,14 @@ var version = contractHandler(apicontract.Version, func(c *gin.Context, request
return apicontract.Success(util.Ver)
})
-func currentTime(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- ret.Data = util.CurrentTimeMillis()
-}
-
-func bootProgress(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+var currentTime = contractHandler(apicontract.CurrentTime, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[int64] {
+ return apicontract.Success(util.CurrentTimeMillis())
+})
+var bootProgress = contractHandler(apicontract.BootProgress, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.BootProgressData] {
progress, details := util.GetBootProgressDetails()
- ret.Data = map[string]any{"progress": progress, "details": details}
-}
+ return apicontract.Success(apicontract.BootProgressData{Progress: progress, Details: details})
+})
func getBootAppearance(c *gin.Context) {
if !model.IsLocalRequest(c) {
@@ -1336,39 +1294,21 @@ func setAppearanceMode(c *gin.Context) {
}
}
-func setNetworkServe(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- networkServe := arg["networkServe"].(bool)
- model.Conf.System.NetworkServe = networkServe
+var setNetworkServe = contractHandler(apicontract.SetNetworkServe, func(c *gin.Context, request apicontract.NetworkServeRequest) apicontract.Response[apicontract.Null] {
+ model.Conf.System.NetworkServe = request.NetworkServe
model.Conf.Save()
-
util.PushMsg(model.Conf.Language(42), 1000*15)
time.Sleep(time.Second * 3)
-}
-
-func setNetworkServeTLS(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{})
+})
- networkServeTLS := arg["networkServeTLS"].(bool)
- model.Conf.System.NetworkServeTLS = networkServeTLS
+var setNetworkServeTLS = contractHandler(apicontract.SetNetworkServeTLS, func(c *gin.Context, request apicontract.NetworkServeTLSRequest) apicontract.Response[apicontract.Null] {
+ model.Conf.System.NetworkServeTLS = request.NetworkServeTLS
model.Conf.Save()
-
util.PushMsg(model.Conf.Language(42), 1000*15)
time.Sleep(time.Second * 3)
-}
+ return apicontract.Success(apicontract.Null{})
+})
func exportTLSCACert(c *gin.Context) {
ret := gulu.Ret.NewResult()
@@ -1520,78 +1460,33 @@ func importTLSCABundle(c *gin.Context) {
}
}
-func setAutoLaunch(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- autoLaunch := int(arg["autoLaunch"].(float64))
- model.Conf.System.AutoLaunch2 = autoLaunch
+var setAutoLaunch = contractHandler(apicontract.SetAutoLaunch, func(c *gin.Context, request apicontract.AutoLaunchRequest) apicontract.Response[apicontract.Null] {
+ model.Conf.System.AutoLaunch2 = int(request.AutoLaunch)
model.Conf.Save()
-}
-
-func setDownloadInstallPkg(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{})
+})
- downloadInstallPkg := arg["downloadInstallPkg"].(bool)
- model.Conf.System.DownloadInstallPkg = downloadInstallPkg
+var setDownloadInstallPkg = contractHandler(apicontract.SetDownloadInstallPkg, func(c *gin.Context, request apicontract.DownloadInstallPkgRequest) apicontract.Response[apicontract.Null] {
+ model.Conf.System.DownloadInstallPkg = request.DownloadInstallPkg
model.Conf.Save()
-}
-
-func setUpdateChannel(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- updateChannel, ok := arg["updateChannel"].(string)
- if !ok {
- ret.Code = -1
- ret.Msg = "update channel is invalid"
- return
- }
- if err := model.SetUpdateChannel(updateChannel); err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- }
-}
-
-func setNetworkProxy(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
+ return apicontract.Success(apicontract.Null{})
+})
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+var setUpdateChannel = contractHandler(apicontract.SetUpdateChannel, func(c *gin.Context, request apicontract.UpdateChannelRequest) apicontract.Response[apicontract.Null] {
+ if err := model.SetUpdateChannel(request.UpdateChannel); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
+ return apicontract.Success(apicontract.Null{})
+})
- scheme := arg["scheme"].(string)
- host := arg["host"].(string)
- port := arg["port"].(string)
- model.Conf.System.NetworkProxy = &conf.NetworkProxy{
- Scheme: scheme,
- Host: host,
- Port: port,
- }
+var setNetworkProxy = contractHandler(apicontract.SetNetworkProxy, func(c *gin.Context, request apicontract.NetworkProxy) apicontract.Response[apicontract.Null] {
+ model.Conf.System.NetworkProxy = &conf.NetworkProxy{Scheme: request.Scheme, Host: request.Host, Port: request.Port}
model.Conf.Save()
-
proxyURL := model.Conf.System.NetworkProxy.String()
util.SetNetworkProxy(proxyURL, model.Conf.System.NetworkProxy.IsSystem())
util.PushMsg(model.Conf.Language(102), 3000)
-}
+ return apicontract.Success(apicontract.Null{})
+})
func addUIProcess(c *gin.Context) {
pid := c.Query("pid")
diff --git a/kernel/api/tag.go b/kernel/api/tag.go
index 06abdebf7a..b36428c8ac 100644
--- a/kernel/api/tag.go
+++ b/kernel/api/tag.go
@@ -17,91 +17,50 @@
package api
import (
- "net/http"
-
- "github.com/88250/gulu"
"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 getTag(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+func tagContracts(tags model.Tags) []*apicontract.TagData {
+ if tags == nil {
+ return nil
}
-
- var ignoreMaxListHint bool
- var app string
- var sortVal float64
- if !util.ParseJsonArgs(arg, ret,
- // API `getTag` add an optional parameter `ignoreMaxListHint` https://github.com/siyuan-note/siyuan/issues/16000
- util.BindJsonArg("ignoreMaxListHint", &ignoreMaxListHint, false, false),
- util.BindJsonArg("app", &app, false, false),
- util.BindJsonArg("sort", &sortVal, false, false),
- ) {
- return
+ ret := make([]*apicontract.TagData, len(tags))
+ for i, tag := range tags {
+ if tag != nil {
+ ret[i] = &apicontract.TagData{Name: tag.Name, Label: tag.Label, Children: tagContracts(tag.Children),
+ Type: tag.Type, Depth: tag.Depth, Count: tag.Count}
+ }
}
+ return ret
+}
+var getTag = contractHandler(apicontract.GetTag, func(c *gin.Context, request apicontract.GetTagRequest) apicontract.Response[[]*apicontract.TagData] {
if model.IsAdminRoleContext(c) && !model.IsReadOnlyRoleContext(c) {
- model.Conf.Tag.Sort = int(sortVal)
+ model.Conf.Tag.Sort = int(request.Sort)
model.Conf.Save()
}
-
- tags := model.BuildTags(ignoreMaxListHint, app, int(sortVal))
-
+ tags := model.BuildTags(request.IgnoreMaxListHint, request.App, int(request.Sort))
if model.IsReadOnlyRoleContext(c) {
- publishAccess := model.GetPublishAccess()
- tags = model.FilterTagsByPublishAccess(c, publishAccess, tags)
+ tags = model.FilterTagsByPublishAccess(c, model.GetPublishAccess(), tags)
}
- ret.Data = tags
-}
-
-func renameTag(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if tags == nil {
+ return apicontract.Success[[]*apicontract.TagData](nil)
}
+ return apicontract.Success(tagContracts(*tags))
+})
- var oldLabel, newLabel string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("oldLabel", &oldLabel, true, false),
- util.BindJsonArg("newLabel", &newLabel, true, true),
- ) {
- return
+var renameTag = contractHandler(apicontract.RenameTag, func(c *gin.Context, request apicontract.RenameTagRequest) apicontract.Response[apicontract.Null] {
+ if err := model.RenameTag(request.OldLabel, request.NewLabel); err != nil {
+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 5000)
}
+ return apicontract.Success(apicontract.Null{})
+})
- if err := model.RenameTag(oldLabel, newLabel); err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- ret.Data = map[string]any{"closeTimeout": 5000}
- return
+var removeTag = contractHandler(apicontract.RemoveTag, func(c *gin.Context, request apicontract.RemoveTagRequest) apicontract.Response[apicontract.Null] {
+ if err := model.RemoveTag(request.Label); err != nil {
+ return apicontract.FailureWithTimeout[apicontract.Null](-1, err.Error(), 5000)
}
-}
-
-func removeTag(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var label string
- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("label", &label, true, false)) {
- return
- }
- if err := model.RemoveTag(label); err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- ret.Data = map[string]any{"closeTimeout": 5000}
- return
- }
-}
+ return apicontract.Success(apicontract.Null{})
+})
diff --git a/kernel/apicontract/basics.go b/kernel/apicontract/basics.go
new file mode 100644
index 0000000000..4e7e9445f6
--- /dev/null
+++ b/kernel/apicontract/basics.go
@@ -0,0 +1,98 @@
+package apicontract
+
+type WorkspaceInfoData struct {
+ WorkspaceDir string `json:"workspaceDir"`
+ SiyuanVer string `json:"siyuanVer"`
+}
+
+type BootProgressData struct {
+ Progress int32 `json:"progress"`
+ Details string `json:"details"`
+}
+
+type NetworkProxy struct {
+ Scheme string `json:"scheme"`
+ Host string `json:"host"`
+ Port string `json:"port"`
+}
+
+type NetworkData struct {
+ Proxy *NetworkProxy `json:"proxy"`
+}
+
+type LockScreenRequest struct {
+ LockScreenMode float64 `json:"lockScreenMode"`
+}
+
+type NetworkServeRequest struct {
+ NetworkServe bool `json:"networkServe"`
+}
+
+type NetworkServeTLSRequest struct {
+ NetworkServeTLS bool `json:"networkServeTLS"`
+}
+
+type AutoLaunchRequest struct {
+ AutoLaunch float64 `json:"autoLaunch"`
+}
+
+type DownloadInstallPkgRequest struct {
+ DownloadInstallPkg bool `json:"downloadInstallPkg"`
+}
+
+type UpdateChannelRequest struct {
+ UpdateChannel string `json:"updateChannel"`
+}
+
+type BlockIDsRequest struct {
+ IDs []string `json:"ids"`
+}
+
+type DOMTextRequest struct {
+ DOM string `json:"dom"`
+}
+
+type RemoveBookmarkRequest struct {
+ Bookmark string `json:"bookmark"`
+}
+
+type RenameBookmarkRequest struct {
+ OldBookmark string `json:"oldBookmark"`
+ NewBookmark string `json:"newBookmark"`
+}
+
+type RemoveTagRequest struct {
+ Label string `json:"label"`
+}
+
+type RenameTagRequest struct {
+ OldLabel string `json:"oldLabel"`
+ NewLabel string `json:"newLabel" api:"trim"`
+}
+
+type BatchSetBlockAttrsRequest struct {
+ BlockAttrs []SetBlockAttrsRequest `json:"blockAttrs"`
+}
+
+type EditorReadOnlyRequest struct {
+ ReadOnly bool `json:"readonly"`
+}
+
+type VirtualBlockRefRequest struct {
+ Keywords []string `json:"keywords"`
+}
+
+type GetTagRequest struct {
+ IgnoreMaxListHint bool `json:"ignoreMaxListHint" api:"optional,nullable"`
+ App string `json:"app" api:"optional,nullable"`
+ Sort float64 `json:"sort" api:"optional,nullable"`
+}
+
+type TagData struct {
+ Name string `json:"name"`
+ Label string `json:"label"`
+ Children []*TagData `json:"children"`
+ Type string `json:"type"`
+ Depth int `json:"depth"`
+ Count int `json:"count"`
+}
diff --git a/kernel/apicontract/basics_test.go b/kernel/apicontract/basics_test.go
new file mode 100644
index 0000000000..36169ba3e4
--- /dev/null
+++ b/kernel/apicontract/basics_test.go
@@ -0,0 +1,52 @@
+package apicontract
+
+import (
+ "encoding/json"
+ "strings"
+ "testing"
+)
+
+func TestBatchRequestConstraints(t *testing.T) {
+ for _, body := range []string{`{}`, `{"ids":null}`, `{"ids":[null]}`, `{"ids":[1]}`} {
+ if _, err := BatchGetBlockAttrs.Decode(strings.NewReader(body)); err == nil {
+ t.Fatalf("invalid IDs accepted: %s", body)
+ }
+ }
+ for _, body := range []string{`{"blockAttrs":[null]}`, `{"blockAttrs":[{}]}`, `{"blockAttrs":[{"ID":"id","attrs":{}}]}`, `{"blockAttrs":[{"id":"id"}]}`, `{"blockAttrs":[{"id":"id","attrs":null}]}`, `{"blockAttrs":[{"id":"id","attrs":{"x":1}}]}`} {
+ if _, err := BatchSetBlockAttrs.Decode(strings.NewReader(body)); err == nil {
+ t.Fatalf("invalid nested attributes accepted: %s", body)
+ }
+ }
+ request, err := BatchSetBlockAttrs.Decode(strings.NewReader(`{"blockAttrs":[{"id":"id","attrs":{"remove":null,"name":"value"}}]}`))
+ if err != nil || len(request.BlockAttrs) != 1 || request.BlockAttrs[0].Attrs["remove"] != nil || *request.BlockAttrs[0].Attrs["name"] != "value" {
+ t.Fatalf("nullable attribute values changed: %+v, %v", request, err)
+ }
+ for _, body := range []string{`{}`, `{"app":null,"sort":null,"ignoreMaxListHint":null}`} {
+ request, err := GetTag.Decode(strings.NewReader(body))
+ if err != nil || request.App != "" || request.Sort != 0 || request.IgnoreMaxListHint {
+ t.Fatalf("optional tag defaults changed: %+v, %v", request, err)
+ }
+ }
+ requestTag, err := RenameTag.Decode(strings.NewReader(`{"oldLabel":" old ","newLabel":" new "}`))
+ if err != nil || requestTag.OldLabel != " old " || requestTag.NewLabel != "new" {
+ t.Fatalf("label trimming changed: %+v, %v", requestTag, err)
+ }
+ requestLaunch, err := SetAutoLaunch.Decode(strings.NewReader(`{"autoLaunch":1.9}`))
+ if err != nil || requestLaunch.AutoLaunch != 1.9 {
+ t.Fatalf("numeric input was truncated during decoding: %+v, %v", requestLaunch, err)
+ }
+}
+
+func TestTimeoutResponseContract(t *testing.T) {
+ bundle, err := BuildBundle()
+ if err != nil {
+ t.Fatal(err)
+ }
+ response, err := json.Marshal(FailureWithTimeout[Null](-1, "failed", 5000))
+ if err != nil || string(response) != `{"code":-1,"msg":"failed","data":{"closeTimeout":5000}}` {
+ t.Fatalf("timeout envelope changed: %s, %v", response, err)
+ }
+ if err := bundle.ValidateResponse("POST", "/api/tag/renameTag", response); err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/kernel/apicontract/block.go b/kernel/apicontract/block.go
new file mode 100644
index 0000000000..0c0600ff9c
--- /dev/null
+++ b/kernel/apicontract/block.go
@@ -0,0 +1,48 @@
+package apicontract
+
+type BlockQueryRequest struct {
+ ID string `json:"id"`
+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`
+ IDs []string `json:"ids" api:"optional,filterstrings"`
+}
+
+type BlocksQueryRequest struct {
+ IDs []string `json:"ids"`
+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`
+ ID string `json:"id" api:"optional,nullable,ignoretype"`
+}
+
+type BlockSiblingData struct {
+ Parent string `json:"parent"`
+ Next string `json:"next"`
+ Previous string `json:"previous"`
+}
+
+type BlockRelevantData struct {
+ ParentID string `json:"parentID"`
+ PreviousID string `json:"previousID"`
+ NextID string `json:"nextID"`
+}
+
+type UnfoldedParentData struct {
+ ParentID string `json:"parentID"`
+}
+
+type BlockFoldData struct {
+ IsFolded bool `json:"isFolded"`
+ IsRoot bool `json:"isRoot"`
+}
+
+type HeadingChildrenRequest struct {
+ ID string `json:"id"`
+ RemoveFoldAttr *bool `json:"removeFoldAttr" api:"optional"`
+}
+
+type AppendHeadingChildrenRequest struct {
+ ID string `json:"id"`
+ ChildrenDOM string `json:"childrenDOM"`
+}
+
+type DocOrdersRequest struct {
+ ID string `json:"id" api:"trim"`
+}
diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.go
index 36e6009097..4abc4ba2b5 100644
--- a/kernel/apicontract/contracts.go
+++ b/kernel/apicontract/contracts.go
@@ -154,3 +154,55 @@ type PublishedBlockInfo struct {
func (FullBlockInfo) blockInfoData() {}
func (PublishedBlockInfo) blockInfoData() {}
+
+var (
+ ClearTempFiles = define[EmptyRequest, Null]("clearTempFiles", "/api/system/clearTempFiles", NoBody, ResponseOptions{}, "POST")
+ VacuumDataIndex = define[EmptyRequest, Null]("vacuumDataIndex", "/api/system/vacuumDataIndex", NoBody, ResponseOptions{}, "POST")
+ RebuildDataIndex = define[EmptyRequest, Null]("rebuildDataIndex", "/api/system/rebuildDataIndex", NoBody, ResponseOptions{}, "POST")
+ IgnoreAddMicrosoftDefenderExclusion = define[EmptyRequest, Null]("ignoreAddMicrosoftDefenderExclusion", "/api/system/ignoreAddMicrosoftDefenderExclusion", NoBody, ResponseOptions{}, "POST")
+ AddMicrosoftDefenderExclusion = define[EmptyRequest, Null]("addMicrosoftDefenderExclusion", "/api/system/addMicrosoftDefenderExclusion", NoBody, ResponseOptions{}, "POST")
+ GetWorkspaceInfo = define[EmptyRequest, WorkspaceInfoData]("getWorkspaceInfo", "/api/system/getWorkspaceInfo", NoBody, ResponseOptions{}, "POST")
+ GetNetwork = define[EmptyRequest, NetworkData]("getNetwork", "/api/system/getNetwork", NoBody, ResponseOptions{}, "POST")
+ CurrentTime = define[EmptyRequest, int64]("currentTime", "/api/system/currentTime", NoBody, ResponseOptions{}, "POST")
+ BootProgress = define[EmptyRequest, BootProgressData]("bootProgress", "/api/system/bootProgress", NoBody, ResponseOptions{}, "GET", "POST")
+ SetFollowSystemLockScreen = define[LockScreenRequest, Null]("setFollowSystemLockScreen", "/api/system/setFollowSystemLockScreen", JSONBody, ResponseOptions{}, "POST")
+ SetAutoLaunch = define[AutoLaunchRequest, Null]("setAutoLaunch", "/api/system/setAutoLaunch", JSONBody, ResponseOptions{}, "POST")
+ SetDownloadInstallPkg = define[DownloadInstallPkgRequest, Null]("setDownloadInstallPkg", "/api/system/setDownloadInstallPkg", JSONBody, ResponseOptions{}, "POST")
+ SetNetworkServe = define[NetworkServeRequest, Null]("setNetworkServe", "/api/system/setNetworkServe", JSONBody, ResponseOptions{}, "POST")
+ SetNetworkServeTLS = define[NetworkServeTLSRequest, Null]("setNetworkServeTLS", "/api/system/setNetworkServeTLS", JSONBody, ResponseOptions{}, "POST")
+ SetUpdateChannel = define[UpdateChannelRequest, Null]("setUpdateChannel", "/api/system/setUpdateChannel", JSONBody, ResponseOptions{}, "POST")
+ SetNetworkProxy = define[NetworkProxy, Null]("setNetworkProxy", "/api/system/setNetworkProxy", JSONBody, ResponseOptions{}, "POST")
+ GetBookmarkLabels = define[EmptyRequest, []string]("getBookmarkLabels", "/api/attr/getBookmarkLabels", NoBody, ResponseOptions{}, "POST")
+ BatchGetBlockAttrs = define[BlockIDsRequest, map[string]map[string]string]("batchGetBlockAttrs", "/api/attr/batchGetBlockAttrs", JSONBody, ResponseOptions{NonNullable: true}, "POST")
+ GetDOMText = define[DOMTextRequest, string]("getDOMText", "/api/block/getDOMText", JSONBody, ResponseOptions{}, "POST")
+ RemoveBookmark = define[RemoveBookmarkRequest, Null]("removeBookmark", "/api/bookmark/removeBookmark", JSONBody, ResponseOptions{}, "POST")
+ RenameBookmark = define[RenameBookmarkRequest, Null]("renameBookmark", "/api/bookmark/renameBookmark", JSONBody, ResponseOptions{}, "POST")
+ RemoveTag = define[RemoveTagRequest, Null]("removeTag", "/api/tag/removeTag", JSONBody, ResponseOptions{}, "POST")
+ RenameTag = define[RenameTagRequest, Null]("renameTag", "/api/tag/renameTag", JSONBody, ResponseOptions{}, "POST")
+)
+
+var (
+ SetEditorReadOnly = define[EditorReadOnlyRequest, Null]("setEditorReadOnly", "/api/setting/setEditorReadOnly", JSONBody, ResponseOptions{}, "POST")
+ AddVirtualBlockRefExclude = define[VirtualBlockRefRequest, Null]("addVirtualBlockRefExclude", "/api/setting/addVirtualBlockRefExclude", JSONBody, ResponseOptions{}, "POST")
+ AddVirtualBlockRefInclude = define[VirtualBlockRefRequest, Null]("addVirtualBlockRefInclude", "/api/setting/addVirtualBlockRefInclude", JSONBody, ResponseOptions{}, "POST")
+ RefreshVirtualBlockRef = define[EmptyRequest, Null]("refreshVirtualBlockRef", "/api/setting/refreshVirtualBlockRef", NoBody, ResponseOptions{}, "POST")
+ GetPandocBin = define[EmptyRequest, string]("getPandocBin", "/api/setting/getPandocBin", NoBody, ResponseOptions{}, "POST")
+ ReindexHistory = define[EmptyRequest, Null]("reindexHistory", "/api/history/reindexHistory", NoBody, ResponseOptions{}, "POST")
+ ClearWorkspaceHistory = define[EmptyRequest, Null]("clearWorkspaceHistory", "/api/history/clearWorkspaceHistory", NoBody, ResponseOptions{}, "POST")
+ BatchSetBlockAttrs = define[BatchSetBlockAttrsRequest, Null]("batchSetBlockAttrs", "/api/attr/batchSetBlockAttrs", JSONBody, ResponseOptions{}, "POST")
+ GetTag = define[GetTagRequest, []*TagData]("getTag", "/api/tag/getTag", JSONBody, ResponseOptions{}, "POST")
+)
+
+var (
+ GetBlockSiblingID = define[BlockQueryRequest, BlockSiblingData]("getBlockSiblingID", "/api/block/getBlockSiblingID", JSONBody, ResponseOptions{}, "POST")
+ GetBlockRelevantIDs = define[BlockQueryRequest, BlockRelevantData]("getBlockRelevantIDs", "/api/block/getBlockRelevantIDs", JSONBody, ResponseOptions{}, "POST")
+ GetUnfoldedParentID = define[BlockQueryRequest, UnfoldedParentData]("getUnfoldedParentID", "/api/block/getUnfoldedParentID", JSONBody, ResponseOptions{}, "POST")
+ CheckBlockFold = define[BlockQueryRequest, BlockFoldData]("checkBlockFold", "/api/block/checkBlockFold", JSONBody, ResponseOptions{}, "POST")
+ CheckBlockExist = define[BlockQueryRequest, bool]("checkBlockExist", "/api/block/checkBlockExist", JSONBody, ResponseOptions{}, "POST")
+ GetBlockIndex = define[BlockQueryRequest, int]("getBlockIndex", "/api/block/getBlockIndex", JSONBody, ResponseOptions{}, "POST")
+ GetBlocksIndexes = define[BlocksQueryRequest, map[string]int]("getBlocksIndexes", "/api/block/getBlocksIndexes", JSONBody, ResponseOptions{}, "POST")
+ GetHeadingChildrenIDs = define[BlockIDRequest, []string]("getHeadingChildrenIDs", "/api/block/getHeadingChildrenIDs", JSONBody, ResponseOptions{}, "POST")
+ GetHeadingChildrenDOM = define[HeadingChildrenRequest, string]("getHeadingChildrenDOM", "/api/block/getHeadingChildrenDOM", JSONBody, ResponseOptions{}, "POST")
+ AppendHeadingChildren = define[AppendHeadingChildrenRequest, Null]("appendHeadingChildren", "/api/block/appendHeadingChildren", JSONBody, ResponseOptions{}, "POST")
+ GetDocBlocksOrders = define[DocOrdersRequest, []string]("getDocBlocksOrders", "/api/block/getDocBlocksOrders", JSONBody, ResponseOptions{}, "POST")
+)
diff --git a/kernel/apicontract/decode.go b/kernel/apicontract/decode.go
index 46b4e87912..a26d2b6327 100644
--- a/kernel/apicontract/decode.go
+++ b/kernel/apicontract/decode.go
@@ -80,11 +80,17 @@ func decodeRequestFields(value reflect.Value, fields map[string]json.RawMessage)
}
continue
}
- if err := json.Unmarshal(raw, value.Field(i).Addr().Interface()); err != nil {
+ var decodeErr error
+ if isNull && has("nullable") {
+ value.Field(i).SetZero()
+ } else {
+ decodeErr = decodeRequestValue(raw, value.Field(i))
+ }
+ if decodeErr != nil {
if has("ignoretype") {
continue
}
- return fmt.Errorf("Field [%s] has an invalid type: %w", name, err)
+ return fmt.Errorf("Field [%s] has an invalid type: %w", name, decodeErr)
}
if has("trim") {
trimmed := strings.TrimSpace(value.Field(i).String())
@@ -129,3 +135,55 @@ func decodeRequestFields(value reflect.Value, fields map[string]json.RawMessage)
}
return nil
}
+
+// decodeRequestValue 递归绑定复合参数,避免数组元素和嵌套字段绕过空值及必填检查。
+func decodeRequestValue(raw json.RawMessage, value reflect.Value) error {
+ if bytes.Equal(bytes.TrimSpace(raw), []byte("null")) {
+ switch value.Kind() {
+ case reflect.Pointer, reflect.Map, reflect.Slice:
+ value.SetZero()
+ return nil
+ default:
+ return fmt.Errorf("value must not be null")
+ }
+ }
+ switch value.Kind() {
+ case reflect.Pointer:
+ value.Set(reflect.New(value.Type().Elem()))
+ return decodeRequestValue(raw, value.Elem())
+ case reflect.Struct:
+ var fields map[string]json.RawMessage
+ if err := json.Unmarshal(raw, &fields); err != nil {
+ return err
+ }
+ return decodeRequestFields(value, fields)
+ case reflect.Slice:
+ var entries []json.RawMessage
+ if err := json.Unmarshal(raw, &entries); err != nil {
+ return err
+ }
+ value.Set(reflect.MakeSlice(value.Type(), len(entries), len(entries)))
+ for i, entry := range entries {
+ if err := decodeRequestValue(entry, value.Index(i)); err != nil {
+ return fmt.Errorf("element [%d]: %w", i, err)
+ }
+ }
+ return nil
+ case reflect.Map:
+ var entries map[string]json.RawMessage
+ if err := json.Unmarshal(raw, &entries); err != nil {
+ return err
+ }
+ value.Set(reflect.MakeMapWithSize(value.Type(), len(entries)))
+ for key, entry := range entries {
+ child := reflect.New(value.Type().Elem()).Elem()
+ if err := decodeRequestValue(entry, child); err != nil {
+ return fmt.Errorf("entry [%s]: %w", key, err)
+ }
+ value.SetMapIndex(reflect.ValueOf(key).Convert(value.Type().Key()), child)
+ }
+ return nil
+ default:
+ return json.Unmarshal(raw, value.Addr().Interface())
+ }
+}
diff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.json
index 61378994f7..da919c215a 100644
--- a/kernel/apicontract/legacy_routes.json
+++ b/kernel/apicontract/legacy_routes.json
@@ -8,7 +8,6 @@
{"method":"GET","path":"/api/plugin","handler":"listLoadedPlugins"},
{"method":"GET","path":"/api/plugin/rpc","handler":"getLoadedPlugin"},
{"method":"GET","path":"/api/plugin/rpc/:name","handler":"getLoadedPlugin"},
- {"method":"GET","path":"/api/system/bootProgress","handler":"bootProgress"},
{"method":"GET","path":"/api/system/bootProgressSSE","handler":"bootProgressSSE"},
{"method":"GET","path":"/api/system/getBootAppearance","handler":"getBootAppearance"},
{"method":"GET","path":"/api/system/getCaptcha","handler":"model.GetCaptcha"},
@@ -80,9 +79,6 @@
{"method":"POST","path":"/api/asset/upload","handler":"model.Upload"},
{"method":"POST","path":"/api/asset/uploadCloud","handler":"uploadCloud"},
{"method":"POST","path":"/api/asset/uploadCloudByAssetsPaths","handler":"uploadCloudByAssetsPaths"},
- {"method":"POST","path":"/api/attr/batchGetBlockAttrs","handler":"batchGetBlockAttrs"},
- {"method":"POST","path":"/api/attr/batchSetBlockAttrs","handler":"batchSetBlockAttrs"},
- {"method":"POST","path":"/api/attr/getBookmarkLabels","handler":"getBookmarkLabels"},
{"method":"POST","path":"/api/attr/resetBlockAttrs","handler":"deprecated"},
{"method":"POST","path":"/api/av/addAttributeViewBlocks","handler":"addAttributeViewBlocks"},
{"method":"POST","path":"/api/av/addAttributeViewKey","handler":"addAttributeViewKey"},
@@ -165,14 +161,11 @@
{"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/appendHeadingChildren","handler":"appendHeadingChildren"},
{"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/checkBlockExist","handler":"checkBlockExist"},
- {"method":"POST","path":"/api/block/checkBlockFold","handler":"checkBlockFold"},
{"method":"POST","path":"/api/block/checkBlockRef","handler":"checkBlockRef"},
{"method":"POST","path":"/api/block/checkBlocksExist","handler":"checkBlocksExist"},
{"method":"POST","path":"/api/block/deleteBlock","handler":"deleteBlock"},
@@ -184,23 +177,15 @@
{"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/getBlockIndex","handler":"getBlockIndex"},
{"method":"POST","path":"/api/block/getBlockKramdown","handler":"getBlockKramdown"},
{"method":"POST","path":"/api/block/getBlockKramdowns","handler":"getBlockKramdowns"},
- {"method":"POST","path":"/api/block/getBlockRelevantIDs","handler":"getBlockRelevantIDs"},
- {"method":"POST","path":"/api/block/getBlockSiblingID","handler":"getBlockSiblingID"},
{"method":"POST","path":"/api/block/getBlockTreeInfos","handler":"getBlockTreeInfos"},
- {"method":"POST","path":"/api/block/getBlocksIndexes","handler":"getBlocksIndexes"},
{"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/getDOMText","handler":"getDOMText"},
- {"method":"POST","path":"/api/block/getDocBlocksOrders","handler":"getDocBlocksOrders"},
{"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/getHeadingChildrenDOM","handler":"getHeadingChildrenDOM"},
- {"method":"POST","path":"/api/block/getHeadingChildrenIDs","handler":"getHeadingChildrenIDs"},
{"method":"POST","path":"/api/block/getHeadingDeleteTransaction","handler":"getHeadingDeleteTransaction"},
{"method":"POST","path":"/api/block/getHeadingFoldTransaction","handler":"getHeadingFoldTransaction"},
{"method":"POST","path":"/api/block/getHeadingInsertTransaction","handler":"getHeadingInsertTransaction"},
@@ -212,7 +197,6 @@
{"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/getUnfoldedParentID","handler":"getUnfoldedParentID"},
{"method":"POST","path":"/api/block/insertBlock","handler":"insertBlock"},
{"method":"POST","path":"/api/block/moveBlock","handler":"moveBlock"},
{"method":"POST","path":"/api/block/moveOutlineHeading","handler":"moveOutlineHeading"},
@@ -225,8 +209,6 @@
{"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/bookmark/removeBookmark","handler":"removeBookmark"},
- {"method":"POST","path":"/api/bookmark/renameBookmark","handler":"renameBookmark"},
{"method":"POST","path":"/api/broadcast/getChannelInfo","handler":"getChannelInfo"},
{"method":"POST","path":"/api/broadcast/getChannels","handler":"getChannels"},
{"method":"POST","path":"/api/broadcast/postMessage","handler":"postMessage"},
@@ -327,14 +309,12 @@
{"method":"POST","path":"/api/graph/resetGraph","handler":"resetGraph"},
{"method":"POST","path":"/api/graph/resetLocalGraph","handler":"resetLocalGraph"},
{"method":"POST","path":"/api/graph/setGraphConf","handler":"setGraphConf"},
- {"method":"POST","path":"/api/history/clearWorkspaceHistory","handler":"clearWorkspaceHistory"},
{"method":"POST","path":"/api/history/createAssetHistory","handler":"createAssetHistory"},
{"method":"POST","path":"/api/history/createDocHistory","handler":"createDocHistory"},
{"method":"POST","path":"/api/history/diffDocVersions","handler":"diffDocVersions"},
{"method":"POST","path":"/api/history/getDocHistoryContent","handler":"getDocHistoryContent"},
{"method":"POST","path":"/api/history/getHistoryItems","handler":"getHistoryItems"},
{"method":"POST","path":"/api/history/getNotebookHistory","handler":"getNotebookHistory"},
- {"method":"POST","path":"/api/history/reindexHistory","handler":"reindexHistory"},
{"method":"POST","path":"/api/history/rollbackAssetsHistory","handler":"rollbackAssetsHistory"},
{"method":"POST","path":"/api/history/rollbackAttributeViewHistory","handler":"rollbackAttributeViewHistory"},
{"method":"POST","path":"/api/history/rollbackDocHistory","handler":"rollbackDocHistory"},
@@ -456,22 +436,17 @@
{"method":"POST","path":"/api/search/searchWidget","handler":"searchWidget"},
{"method":"POST","path":"/api/search/semanticSearchBlock","handler":"semanticSearchBlock"},
{"method":"POST","path":"/api/search/updateEmbedBlock","handler":"updateEmbedBlock"},
- {"method":"POST","path":"/api/setting/addVirtualBlockRefExclude","handler":"addVirtualBlockRefExclude"},
- {"method":"POST","path":"/api/setting/addVirtualBlockRefInclude","handler":"addVirtualBlockRefInclude"},
{"method":"POST","path":"/api/setting/getBootAppearances","handler":"getBootAppearances"},
{"method":"POST","path":"/api/setting/getCloudUser","handler":"getCloudUser"},
- {"method":"POST","path":"/api/setting/getPandocBin","handler":"getPandocBin"},
{"method":"POST","path":"/api/setting/getPublish","handler":"getPublish"},
{"method":"POST","path":"/api/setting/login2faCloudUser","handler":"login2faCloudUser"},
{"method":"POST","path":"/api/setting/logoutCloudUser","handler":"logoutCloudUser"},
- {"method":"POST","path":"/api/setting/refreshVirtualBlockRef","handler":"refreshVirtualBlockRef"},
{"method":"POST","path":"/api/setting/setAI","handler":"setAI"},
{"method":"POST","path":"/api/setting/setAppearance","handler":"setAppearance"},
{"method":"POST","path":"/api/setting/setBazaar","handler":"setBazaar"},
{"method":"POST","path":"/api/setting/setBazaarPetalDisabled","handler":"setBazaarPetalDisabled"},
{"method":"POST","path":"/api/setting/setBootAppearance","handler":"setBootAppearance"},
{"method":"POST","path":"/api/setting/setEditor","handler":"setEditor"},
- {"method":"POST","path":"/api/setting/setEditorReadOnly","handler":"setEditorReadOnly"},
{"method":"POST","path":"/api/setting/setEmoji","handler":"setEmoji"},
{"method":"POST","path":"/api/setting/setEntryVisibility","handler":"setEntryVisibility"},
{"method":"POST","path":"/api/setting/setExport","handler":"setExport"},
@@ -539,13 +514,9 @@
{"method":"POST","path":"/api/sync/setSyncProviderS3","handler":"setSyncProviderS3"},
{"method":"POST","path":"/api/sync/setSyncProviderWebDAV","handler":"setSyncProviderWebDAV"},
{"method":"POST","path":"/api/system/addCustomEmoji","handler":"addCustomEmoji"},
- {"method":"POST","path":"/api/system/addMicrosoftDefenderExclusion","handler":"addMicrosoftDefenderExclusion"},
- {"method":"POST","path":"/api/system/bootProgress","handler":"bootProgress"},
{"method":"POST","path":"/api/system/checkUpdate","handler":"checkUpdate"},
{"method":"POST","path":"/api/system/checkWorkspaceDir","handler":"checkWorkspaceDir"},
- {"method":"POST","path":"/api/system/clearTempFiles","handler":"clearTempFiles"},
{"method":"POST","path":"/api/system/createWorkspaceDir","handler":"createWorkspaceDir"},
- {"method":"POST","path":"/api/system/currentTime","handler":"currentTime"},
{"method":"POST","path":"/api/system/dismissOnboarding","handler":"dismissOnboarding"},
{"method":"POST","path":"/api/system/ensureOnboarding","handler":"ensureOnboarding"},
{"method":"POST","path":"/api/system/exit","handler":"exit"},
@@ -558,11 +529,8 @@
{"method":"POST","path":"/api/system/getCustomFonts","handler":"getCustomFonts"},
{"method":"POST","path":"/api/system/getEmojiConf","handler":"getEmojiConf"},
{"method":"POST","path":"/api/system/getMobileWorkspaces","handler":"getMobileWorkspaces"},
- {"method":"POST","path":"/api/system/getNetwork","handler":"getNetwork"},
{"method":"POST","path":"/api/system/getSysFonts","handler":"getSysFonts"},
- {"method":"POST","path":"/api/system/getWorkspaceInfo","handler":"getWorkspaceInfo"},
{"method":"POST","path":"/api/system/getWorkspaces","handler":"getWorkspaces"},
- {"method":"POST","path":"/api/system/ignoreAddMicrosoftDefenderExclusion","handler":"ignoreAddMicrosoftDefenderExclusion"},
{"method":"POST","path":"/api/system/importConf","handler":"importConf"},
{"method":"POST","path":"/api/system/importCustomFont","handler":"importCustomFont"},
{"method":"POST","path":"/api/system/importTLSCABundle","handler":"importTLSCABundle"},
@@ -575,7 +543,6 @@
{"method":"POST","path":"/api/system/oidc/validateActivate","handler":"model.OIDCValidateActivate"},
{"method":"POST","path":"/api/system/oidc/validateCancel","handler":"model.OIDCValidateCancel"},
{"method":"POST","path":"/api/system/oidc/validatePoll","handler":"model.OIDCValidatePoll"},
- {"method":"POST","path":"/api/system/rebuildDataIndex","handler":"rebuildDataIndex"},
{"method":"POST","path":"/api/system/reloadUI","handler":"deprecated"},
{"method":"POST","path":"/api/system/removeCustomFont","handler":"removeCustomFont"},
{"method":"POST","path":"/api/system/removeWorkspaceDir","handler":"removeWorkspaceDir"},
@@ -583,21 +550,10 @@
{"method":"POST","path":"/api/system/setAPIToken","handler":"setAPIToken"},
{"method":"POST","path":"/api/system/setAccessAuthCode","handler":"setAccessAuthCode"},
{"method":"POST","path":"/api/system/setAppearanceMode","handler":"setAppearanceMode"},
- {"method":"POST","path":"/api/system/setAutoLaunch","handler":"setAutoLaunch"},
- {"method":"POST","path":"/api/system/setDownloadInstallPkg","handler":"setDownloadInstallPkg"},
- {"method":"POST","path":"/api/system/setFollowSystemLockScreen","handler":"setFollowSystemLockScreen"},
- {"method":"POST","path":"/api/system/setNetworkProxy","handler":"setNetworkProxy"},
- {"method":"POST","path":"/api/system/setNetworkServe","handler":"setNetworkServe"},
- {"method":"POST","path":"/api/system/setNetworkServeTLS","handler":"setNetworkServeTLS"},
{"method":"POST","path":"/api/system/setOIDC","handler":"setOIDC"},
{"method":"POST","path":"/api/system/setUILayout","handler":"setUILayout"},
- {"method":"POST","path":"/api/system/setUpdateChannel","handler":"setUpdateChannel"},
{"method":"POST","path":"/api/system/setWorkspaceDir","handler":"setWorkspaceDir"},
{"method":"POST","path":"/api/system/uiproc","handler":"addUIProcess"},
- {"method":"POST","path":"/api/system/vacuumDataIndex","handler":"vacuumDataIndex"},
- {"method":"POST","path":"/api/tag/getTag","handler":"getTag"},
- {"method":"POST","path":"/api/tag/removeTag","handler":"removeTag"},
- {"method":"POST","path":"/api/tag/renameTag","handler":"renameTag"},
{"method":"POST","path":"/api/template/docSaveAsTemplate","handler":"docSaveAsTemplate"},
{"method":"POST","path":"/api/template/getDocSaveAsTemplateInfo","handler":"getDocSaveAsTemplateInfo"},
{"method":"POST","path":"/api/template/manage","handler":"manageTemplateFiles"},
diff --git a/kernel/apicontract/response.go b/kernel/apicontract/response.go
index ae64c28efe..8c9ce96f8b 100644
--- a/kernel/apicontract/response.go
+++ b/kernel/apicontract/response.go
@@ -24,6 +24,13 @@ func FailureWithText[Data any](code int, msg, data string) Response[Data] {
return Response[Data]{code: code, msg: msg, data: data}
}
+// FailureWithTimeout 保留业务错误提示的显示时长。
+func FailureWithTimeout[Data any](code int, msg string, milliseconds int) Response[Data] {
+ return Response[Data]{code: code, msg: msg, data: struct {
+ CloseTimeout int `json:"closeTimeout"`
+ }{milliseconds}}
+}
+
func (r Response[Data]) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Code int `json:"code"`
diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.json
index 8a50a35d6b..eac15f4297 100644
--- a/kernel/apicontract/schema.json
+++ b/kernel/apicontract/schema.json
@@ -1,6 +1,65 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$defs": {
+ "AppendHeadingChildrenRequestInput": {
+ "type": "object",
+ "properties": {
+ "childrenDOM": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "childrenDOM",
+ "id"
+ ],
+ "additionalProperties": false
+ },
+ "AutoLaunchRequestInput": {
+ "type": "object",
+ "properties": {
+ "autoLaunch": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "autoLaunch"
+ ],
+ "additionalProperties": false
+ },
+ "BatchSetBlockAttrsRequestInput": {
+ "type": "object",
+ "properties": {
+ "blockAttrs": {
+ "type": "array",
+ "items": {
+ "$ref": "#/$defs/SetBlockAttrsRequestInput"
+ }
+ }
+ },
+ "required": [
+ "blockAttrs"
+ ],
+ "additionalProperties": false
+ },
+ "BlockFoldData": {
+ "type": "object",
+ "properties": {
+ "isFolded": {
+ "type": "boolean"
+ },
+ "isRoot": {
+ "type": "boolean"
+ }
+ },
+ "required": [
+ "isFolded",
+ "isRoot"
+ ],
+ "additionalProperties": false
+ },
"BlockIDRequestInput": {
"type": "object",
"properties": {
@@ -13,6 +72,21 @@
],
"additionalProperties": false
},
+ "BlockIDsRequestInput": {
+ "type": "object",
+ "properties": {
+ "ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "required": [
+ "ids"
+ ],
+ "additionalProperties": false
+ },
"BlockInfoData": {
"anyOf": [
{
@@ -58,6 +132,132 @@
],
"additionalProperties": false
},
+ "BlockQueryRequestInput": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "ids": {
+ "anyOf": [
+ {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "notebook": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "id"
+ ],
+ "additionalProperties": false
+ },
+ "BlockRelevantData": {
+ "type": "object",
+ "properties": {
+ "nextID": {
+ "type": "string"
+ },
+ "parentID": {
+ "type": "string"
+ },
+ "previousID": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "nextID",
+ "parentID",
+ "previousID"
+ ],
+ "additionalProperties": false
+ },
+ "BlockSiblingData": {
+ "type": "object",
+ "properties": {
+ "next": {
+ "type": "string"
+ },
+ "parent": {
+ "type": "string"
+ },
+ "previous": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "next",
+ "parent",
+ "previous"
+ ],
+ "additionalProperties": false
+ },
+ "BlocksQueryRequestInput": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "notebook": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "ids"
+ ],
+ "additionalProperties": false
+ },
+ "BootProgressData": {
+ "type": "object",
+ "properties": {
+ "details": {
+ "type": "string"
+ },
+ "progress": {
+ "type": "integer"
+ }
+ },
+ "required": [
+ "details",
+ "progress"
+ ],
+ "additionalProperties": false
+ },
"CheckSnapshotData": {
"type": "object",
"properties": {
@@ -95,6 +295,54 @@
},
"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
@@ -135,6 +383,64 @@
],
"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
+ },
"ListNotebooksData": {
"type": "object",
"properties": {
@@ -184,13 +490,108 @@
},
"additionalProperties": false
},
- "Notebook": {
+ "LockScreenRequestInput": {
"type": "object",
"properties": {
- "closed": {
- "type": "boolean"
- },
- "dueFlashcardCount": {
+ "lockScreenMode": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "lockScreenMode"
+ ],
+ "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": {
@@ -281,6 +682,62 @@
],
"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
+ },
+ "RenameTagRequestInput": {
+ "type": "object",
+ "properties": {
+ "newLabel": {
+ "type": "string"
+ },
+ "oldLabel": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "newLabel",
+ "oldLabel"
+ ],
+ "additionalProperties": false
+ },
"SearchHistoryData": {
"type": "object",
"properties": {
@@ -408,44 +865,3365 @@
{
"type": "string"
},
- {
- "type": "null"
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "id": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "attrs",
+ "id"
+ ],
+ "additionalProperties": false
+ },
+ "SetSnapshotMemoRequestInput": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "memo": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "id",
+ "memo"
+ ],
+ "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
+ },
+ "UnfoldedParentData": {
+ "type": "object",
+ "properties": {
+ "parentID": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "parentID"
+ ],
+ "additionalProperties": false
+ },
+ "UpdateChannelRequestInput": {
+ "type": "object",
+ "properties": {
+ "updateChannel": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "updateChannel"
+ ],
+ "additionalProperties": false
+ },
+ "VirtualBlockRefRequestInput": {
+ "type": "object",
+ "properties": {
+ "keywords": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ },
+ "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",
+ "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/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/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/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/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/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/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/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/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/bookmark/removeBookmark",
+ "handler": "removeBookmark",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/RemoveBookmarkRequestInput"
+ },
+ "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/bookmark/renameBookmark",
+ "handler": "renameBookmark",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/RenameBookmarkRequestInput"
+ },
+ "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/history/clearWorkspaceHistory",
+ "handler": "clearWorkspaceHistory",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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/history/reindexHistory",
+ "handler": "reindexHistory",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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/history/searchHistory",
+ "handler": "searchHistory",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/SearchHistoryRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/SearchHistoryData"
+ },
+ "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/notebook/lsNotebooks",
+ "handler": "lsNotebooks",
+ "body": "legacyOptional",
+ "request": {
+ "$ref": "#/$defs/ListNotebooksRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/ListNotebooksData"
+ },
+ {
+ "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/repo/checkSnapshot",
+ "handler": "checkSnapshot",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/CheckSnapshotData"
+ },
+ "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/repo/createSnapshot",
+ "handler": "createSnapshot",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/CreateSnapshotRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/CreateSnapshotData"
+ },
+ "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/repo/setSnapshotMemo",
+ "handler": "setSnapshotMemo",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/SetSnapshotMemoRequestInput"
+ },
+ "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/search/searchTag",
+ "handler": "searchTag",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/SearchTagRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/SearchTagData"
+ },
+ "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/setting/addVirtualBlockRefExclude",
+ "handler": "addVirtualBlockRefExclude",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/VirtualBlockRefRequestInput"
+ },
+ "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/setting/addVirtualBlockRefInclude",
+ "handler": "addVirtualBlockRefInclude",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/VirtualBlockRefRequestInput"
+ },
+ "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/setting/getPandocBin",
+ "handler": "getPandocBin",
+ "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/setting/refreshVirtualBlockRef",
+ "handler": "refreshVirtualBlockRef",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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/setting/setEditorReadOnly",
+ "handler": "setEditorReadOnly",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/EditorReadOnlyRequestInput"
+ },
+ "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/system/addMicrosoftDefenderExclusion",
+ "handler": "addMicrosoftDefenderExclusion",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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/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": "POST",
+ "path": "/api/system/clearTempFiles",
+ "handler": "clearTempFiles",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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/system/currentTime",
+ "handler": "currentTime",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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/system/getNetwork",
+ "handler": "getNetwork",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/NetworkData"
+ },
+ "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/system/getWorkspaceInfo",
+ "handler": "getWorkspaceInfo",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/WorkspaceInfoData"
+ },
+ "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/system/ignoreAddMicrosoftDefenderExclusion",
+ "handler": "ignoreAddMicrosoftDefenderExclusion",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "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
}
- },
- "id": {
- "type": "string"
- }
- },
- "required": [
- "attrs",
- "id"
- ],
- "additionalProperties": false
+ ]
+ }
},
- "SetSnapshotMemoRequestInput": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "memo": {
- "type": "string"
- }
- },
- "required": [
- "id",
- "memo"
- ],
- "additionalProperties": false
- }
- },
- "endpoints": [
{
- "method": "GET",
- "path": "/api/system/version",
- "handler": "version",
+ "method": "POST",
+ "path": "/api/system/rebuildDataIndex",
+ "handler": "rebuildDataIndex",
"body": "none",
"request": {
"$ref": "#/$defs/EmptyRequestInput"
@@ -462,7 +4240,7 @@
]
},
"data": {
- "type": "string"
+ "type": "null"
},
"msg": {
"type": "string"
@@ -519,11 +4297,11 @@
},
{
"method": "POST",
- "path": "/api/attr/getBlockAttrs",
- "handler": "getBlockAttrs",
+ "path": "/api/system/setAutoLaunch",
+ "handler": "setAutoLaunch",
"body": "json",
"request": {
- "$ref": "#/$defs/BlockIDRequestInput"
+ "$ref": "#/$defs/AutoLaunchRequestInput"
},
"response": {
"anyOf": [
@@ -537,10 +4315,7 @@
]
},
"data": {
- "type": "object",
- "additionalProperties": {
- "type": "string"
- }
+ "type": "null"
},
"msg": {
"type": "string"
@@ -597,11 +4372,11 @@
},
{
"method": "POST",
- "path": "/api/attr/setBlockAttrs",
- "handler": "setBlockAttrs",
+ "path": "/api/system/setDownloadInstallPkg",
+ "handler": "setDownloadInstallPkg",
"body": "json",
"request": {
- "$ref": "#/$defs/SetBlockAttrsRequestInput"
+ "$ref": "#/$defs/DownloadInstallPkgRequestInput"
},
"response": {
"anyOf": [
@@ -672,11 +4447,11 @@
},
{
"method": "POST",
- "path": "/api/block/getBlockInfo",
- "handler": "getBlockInfo",
+ "path": "/api/system/setFollowSystemLockScreen",
+ "handler": "setFollowSystemLockScreen",
"body": "json",
"request": {
- "$ref": "#/$defs/BlockInfoRequestInput"
+ "$ref": "#/$defs/LockScreenRequestInput"
},
"response": {
"anyOf": [
@@ -690,7 +4465,7 @@
]
},
"data": {
- "$ref": "#/$defs/BlockInfoData"
+ "type": "null"
},
"msg": {
"type": "string"
@@ -709,8 +4484,7 @@
"code": {
"type": "integer",
"enum": [
- -1,
- 3
+ -1
]
},
"data": {
@@ -729,9 +4503,81 @@
},
{
"type": "null"
+ }
+ ]
+ },
+ "msg": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "code",
+ "msg",
+ "data"
+ ],
+ "additionalProperties": true
+ }
+ ]
+ }
+ },
+ {
+ "method": "POST",
+ "path": "/api/system/setNetworkProxy",
+ "handler": "setNetworkProxy",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/NetworkProxyInput"
+ },
+ "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": "string"
+ "type": "null"
}
]
},
@@ -751,11 +4597,11 @@
},
{
"method": "POST",
- "path": "/api/history/searchHistory",
- "handler": "searchHistory",
+ "path": "/api/system/setNetworkServe",
+ "handler": "setNetworkServe",
"body": "json",
"request": {
- "$ref": "#/$defs/SearchHistoryRequestInput"
+ "$ref": "#/$defs/NetworkServeRequestInput"
},
"response": {
"anyOf": [
@@ -769,7 +4615,7 @@
]
},
"data": {
- "$ref": "#/$defs/SearchHistoryData"
+ "type": "null"
},
"msg": {
"type": "string"
@@ -826,11 +4672,11 @@
},
{
"method": "POST",
- "path": "/api/notebook/lsNotebooks",
- "handler": "lsNotebooks",
- "body": "legacyOptional",
+ "path": "/api/system/setNetworkServeTLS",
+ "handler": "setNetworkServeTLS",
+ "body": "json",
"request": {
- "$ref": "#/$defs/ListNotebooksRequestInput"
+ "$ref": "#/$defs/NetworkServeTLSRequestInput"
},
"response": {
"anyOf": [
@@ -843,10 +4689,42 @@
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/ListNotebooksData"
+ "type": "object",
+ "properties": {
+ "closeTimeout": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "closeTimeout"
+ ],
+ "additionalProperties": false
},
{
"type": "null"
@@ -862,6 +4740,42 @@
"msg",
"data"
],
+ "additionalProperties": true
+ }
+ ]
+ }
+ },
+ {
+ "method": "POST",
+ "path": "/api/system/setUpdateChannel",
+ "handler": "setUpdateChannel",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/UpdateChannelRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "type": "null"
+ },
+ "msg": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "code",
+ "msg",
+ "data"
+ ],
"additionalProperties": false
},
{
@@ -908,8 +4822,8 @@
},
{
"method": "POST",
- "path": "/api/repo/checkSnapshot",
- "handler": "checkSnapshot",
+ "path": "/api/system/vacuumDataIndex",
+ "handler": "vacuumDataIndex",
"body": "none",
"request": {
"$ref": "#/$defs/EmptyRequestInput"
@@ -926,7 +4840,7 @@
]
},
"data": {
- "$ref": "#/$defs/CheckSnapshotData"
+ "type": "null"
},
"msg": {
"type": "string"
@@ -983,11 +4897,11 @@
},
{
"method": "POST",
- "path": "/api/repo/createSnapshot",
- "handler": "createSnapshot",
- "body": "json",
+ "path": "/api/system/version",
+ "handler": "version",
+ "body": "none",
"request": {
- "$ref": "#/$defs/CreateSnapshotRequestInput"
+ "$ref": "#/$defs/EmptyRequestInput"
},
"response": {
"anyOf": [
@@ -1001,7 +4915,7 @@
]
},
"data": {
- "$ref": "#/$defs/CreateSnapshotData"
+ "type": "string"
},
"msg": {
"type": "string"
@@ -1058,11 +4972,11 @@
},
{
"method": "POST",
- "path": "/api/repo/setSnapshotMemo",
- "handler": "setSnapshotMemo",
+ "path": "/api/tag/getTag",
+ "handler": "getTag",
"body": "json",
"request": {
- "$ref": "#/$defs/SetSnapshotMemoRequestInput"
+ "$ref": "#/$defs/GetTagRequestInput"
},
"response": {
"anyOf": [
@@ -1076,7 +4990,24 @@
]
},
"data": {
- "type": "null"
+ "anyOf": [
+ {
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/TagData"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ {
+ "type": "null"
+ }
+ ]
},
"msg": {
"type": "string"
@@ -1133,11 +5064,11 @@
},
{
"method": "POST",
- "path": "/api/search/searchTag",
- "handler": "searchTag",
+ "path": "/api/tag/removeTag",
+ "handler": "removeTag",
"body": "json",
"request": {
- "$ref": "#/$defs/SearchTagRequestInput"
+ "$ref": "#/$defs/RemoveTagRequestInput"
},
"response": {
"anyOf": [
@@ -1151,7 +5082,7 @@
]
},
"data": {
- "$ref": "#/$defs/SearchTagData"
+ "type": "null"
},
"msg": {
"type": "string"
@@ -1208,11 +5139,11 @@
},
{
"method": "POST",
- "path": "/api/system/version",
- "handler": "version",
- "body": "none",
+ "path": "/api/tag/renameTag",
+ "handler": "renameTag",
+ "body": "json",
"request": {
- "$ref": "#/$defs/EmptyRequestInput"
+ "$ref": "#/$defs/RenameTagRequestInput"
},
"response": {
"anyOf": [
@@ -1226,7 +5157,7 @@
]
},
"data": {
- "type": "string"
+ "type": "null"
},
"msg": {
"type": "string"