Skip to content

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

:recycle: Migrate history API contracts https://github.com/siyuan-note/siyuan/issues/19378

Daniel1bf6ab65c708
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.ts
index af454dca56..fe6794eacc 100644
--- a/app/src/types/api/index.d.ts
+++ b/app/src/types/api/index.d.ts
@@ -164,6 +164,10 @@ export type CopyFilesRequestInput = { "destDir": string; "srcs": Array<string>;
export type CopyStdMarkdownRequestInput = { "adjustHeadingLevel"?: boolean | null; "assetsDestSpace2Underscore"?: boolean | null; "fillCSSVar"?: boolean | null; "id": string; "imgTag"?: boolean | null; };
+export type CreateAssetHistoryRequestInput = { "path": string; };
+
+export type CreateDocHistoryRequestInput = { "id": string; };
+
export type CreateEncryptedNotebookRequestInput = { "name": string; "password": string; };
export type CreateNotebookData = { "notebook": Notebook | null; };
@@ -194,6 +198,8 @@ export type DailyNoteBlockRequestInput = { "data": string; "dataType": string; "
export type DeleteBlockRequestInput = { "id": string; };
+export type DiffDocVersionsRequestInput = { "left": DocVersionRefInput; "right": DocVersionRefInput; };
+
export type DirectoryEntry = { "isDir": boolean; "isSymlink": boolean; "name": string; "updated": number; };
export type DocAttrView = { "id": string; "name": string; };
@@ -202,10 +208,22 @@ export type DocHeadingLevelData = { "counts": Array<number>; "title": string; "t
export type DocHeadingLevelRequestInput = { "id"?: string | null; "notebook"?: string | null; "source"?: number | null; "target"?: number | null; "withSubheadings"?: boolean | null; };
+export type DocHistoryContentData = { "content": string; "id": string; "isLargeDoc": boolean; "rootID": string; };
+
+export type DocHistoryContentRequestInput = { "highlight"?: boolean | null; "historyPath": string; "k"?: string | null; };
+
export type DocInfo = { "attrViews": Array<DocAttrView | null> | null; "ial": Record<string, string> | null; "icon": string; "id": string; "name": string; "refCount": number; "refIDs": Array<string> | null; "rootID": string; "subFileCount": number; };
export type DocOrdersRequestInput = { "id": string; };
+export type DocVersionDiffContent = { "content": string; "id": string; "rootID": string; "title": string; };
+
+export type DocVersionDiffResult = { "differences": Array<DocVersionDifference | null> | null; "fallback": boolean; "large": boolean; "left": DocVersionDiffContent | null; "message": string; "right": DocVersionDiffContent | null; "titleModified": boolean; };
+
+export type DocVersionDifference = { "id": string; "statuses": Array<string> | null; };
+
+export type DocVersionRefInput = { "id"?: string | null; "path"?: string | null; "snapshot"?: string | null; "type": string; };
+
export type DocsInfoRequestInput = { "av": boolean; "ids": Array<string>; "refCount": boolean; };
export type DownloadInstallPkgRequestInput = { "downloadInstallPkg": boolean; };
@@ -272,6 +290,16 @@ export type HeadingLevelRequestInput = { "id"?: string; "ids"?: Array<string>; "
export type HeadingNumbersRequestInput = { "id"?: string | null; "notebook"?: string | null; };
+export type History = { "hCreated": string; "items": Array<HistoryItem | null> | null; };
+
+export type HistoryItem = { "id": string; "notebook": string; "op": string; "path": string; "title": string; };
+
+export type HistoryItemsData = { "items": Array<HistoryItem | null> | null; };
+
+export type HistoryItemsRequestInput = { "created": string; "notebook"?: string | null; "op"?: string | null; "query"?: string | null; "type"?: number | null; };
+
+export type HistoryPathRequestInput = { "historyPath": string; };
+
export type ImportAutoDocument = { "token"?: string; "type": "document"; };
export type ImportAutoNotebook = { "notebook": Notebook | null; "type": "notebook"; };
@@ -382,6 +410,8 @@ export type NotebookEncryption = { "createdAt": number; "metadata"?: string; "sp
export type NotebookEncryptionPatchInput = { "createdAt"?: number | null; "metadata"?: string | Array<number> | null; "spec"?: number | null; "wrapNonce"?: string | Array<number> | null; "wrappedDEK"?: string | Array<number> | null; };
+export type NotebookHistoryData = { "histories": Array<History | null> | null; };
+
export type NotebookIDRequestInput = { "notebook": string; };
export type NotebookInfo = { "ctime": number; "docCount": number; "hCtime": string; "hMtime": string; "hSize": string; "id": string; "mtime": number; "name": string; "size": number; };
@@ -863,16 +893,6 @@ export type APILegacyPOSTPath =
"/api/filetree/setPublishAccess" |
"/api/filetree/setSort" |
"/api/filetree/upsertIndexes" |
- "/api/history/createAssetHistory" |
- "/api/history/createDocHistory" |
- "/api/history/diffDocVersions" |
- "/api/history/getDocHistoryContent" |
- "/api/history/getHistoryItems" |
- "/api/history/getNotebookHistory" |
- "/api/history/rollbackAssetsHistory" |
- "/api/history/rollbackAttributeViewHistory" |
- "/api/history/rollbackDocHistory" |
- "/api/history/rollbackNotebookHistory" |
"/api/network/echo" |
"/api/network/echo/*path" |
"/api/network/forwardProxy" |
@@ -1585,11 +1605,61 @@ export interface APIPOSTRoutes {
response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
body: "none";
};
+ "/api/history/createAssetHistory": {
+ request: CreateAssetHistoryRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/createDocHistory": {
+ request: CreateDocHistoryRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/diffDocVersions": {
+ request: DiffDocVersionsRequestInput;
+ response: { "code": 0; "data": DocVersionDiffResult | null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/getDocHistoryContent": {
+ request: DocHistoryContentRequestInput;
+ response: { "code": 0; "data": DocHistoryContentData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/getHistoryItems": {
+ request: HistoryItemsRequestInput;
+ response: { "code": 0; "data": HistoryItemsData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/getNotebookHistory": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": NotebookHistoryData; "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/rollbackAssetsHistory": {
+ request: HistoryPathRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/rollbackAttributeViewHistory": {
+ request: HistoryPathRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/rollbackDocHistory": {
+ request: HistoryPathRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
+ "/api/history/rollbackNotebookHistory": {
+ request: HistoryPathRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ };
"/api/history/searchHistory": {
request: SearchHistoryRequestInput;
response: { "code": 0; "data": SearchHistoryData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
diff --git a/docs/API-CONTRACTS.md b/docs/API-CONTRACTS.md
index 0a7c475813..b1878531b3 100644
--- a/docs/API-CONTRACTS.md
+++ b/docs/API-CONTRACTS.md
@@ -24,6 +24,8 @@ Encrypted notebook lifecycle endpoints use typed requests and responses while re
## Compatibility requirements
+History contracts retain path trimming, optional highlight defaults, fractional history-type truncation, and null versus empty result arrays. Version comparison checks both reference objects before their fields and acquires notebook leases in sorted order. Content reads and document, asset, and attribute-view rollbacks retain their history-path lease checks; notebook rollback keeps its existing model-level recovery behavior.
+
Import contracts preserve archive cleanup, first-upload selection, untrimmed Markdown paths, and staged-token trimming and lifetime. Automatic SiYuan imports declare document, token, notebook, and notebook-collection results; mount failures retain the document payload. Obsidian task cancellation retains its task snapshot on failure. Notebook mounting, encrypted import handling, and creation notifications remain in the existing business operations.
Backlink contracts preserve untrimmed query fields, optional flag defaults, source-filter normalization, and revision hashes. Missing list IDs still return null; unchanged revisions retain the existing fields with null arrays. Candidate-definition failures retain their empty `refDefs` payload. Publish filtering, encrypted-notebook admission, and request-held leases remain in the handlers, and context payloads retain recursive block paths and attribute-view reference targets.
diff --git a/docs/API-CONTRACTS.zh-CN.md b/docs/API-CONTRACTS.zh-CN.md
index ef81dcb9f1..445ba2a6de 100644
--- a/docs/API-CONTRACTS.zh-CN.md
+++ b/docs/API-CONTRACTS.zh-CN.md
@@ -24,6 +24,8 @@
## 兼容要求
+历史契约保留路径去空白、可选高亮默认值、历史类型的小数截断,以及空值与空数组的区别。版本对比先检查两个引用对象,再检查对象字段,并按排序后的笔记本 ID 获取租约。内容读取及文档、资源和数据库回滚保留历史路径租约检查,笔记本回滚沿用模型层的恢复行为。
+
导入契约保留压缩包清理、首个上传文件选择、Markdown 路径空白,以及暂存令牌去空白和有效期。思源自动导入声明文档、令牌、笔记本和笔记本集合结果,挂载失败时保留文档载荷。Obsidian 任务取消失败时保留任务快照。笔记本挂载、加密导入处理和创建通知仍由既有业务操作负责。
反链契约保留查询字段的空白、可选开关默认值、来源过滤归一化和版本哈希。列表查询缺少 ID 时仍返回空值;版本未变化时保留既有字段和空值数组。候选定义查询失败时保留空的 `refDefs` 数组。发布过滤、加密笔记本准入和请求期间的租约仍由处理器维护,上下文载荷保留递归块路径和数据库引用位置。
diff --git a/kernel/api/contract_history_test.go b/kernel/api/contract_history_test.go
new file mode 100644
index 0000000000..387e2bd3ef
--- /dev/null
+++ b/kernel/api/contract_history_test.go
@@ -0,0 +1,145 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/apicontract"
+ "github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+func TestAPIContractNotebookHistory(t *testing.T) {
+ previousHistory, previousWorkspace := util.HistoryDir, util.WorkspaceDir
+ util.WorkspaceDir = t.TempDir()
+ util.HistoryDir = filepath.Join(util.WorkspaceDir, "history")
+ t.Cleanup(func() { util.HistoryDir, util.WorkspaceDir = previousHistory, previousWorkspace })
+ engine := gin.New()
+ engine.POST("/api/history/getNotebookHistory", getNotebookHistory)
+ call := func() []*apicontract.History {
+ t.Helper()
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/history/getNotebookHistory", strings.NewReader("ignored invalid JSON")))
+ requireAPIContract(t, "POST", "/api/history/getNotebookHistory", recorder)
+ var response struct {
+ Code int `json:"code"`
+ Data apicontract.NotebookHistoryData `json:"data"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != 0 {
+ t.Fatalf("notebook history failed: %s, %v", recorder.Body.String(), err)
+ }
+ return response.Data.Histories
+ }
+ if histories := call(); histories == nil || len(histories) != 0 {
+ t.Fatalf("empty history must return an array: %+v", histories)
+ }
+ for _, date := range []string{"2026-01-01-010203", "2026-01-02-030405"} {
+ folder := filepath.Join(util.HistoryDir, date+"-delete", "box", ".siyuan")
+ if err := os.MkdirAll(folder, 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(folder, "conf.json"), []byte(`{"name":"archived notebook"}`), 0600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ histories := call()
+ if len(histories) != 2 || histories[0].HCreated != "2026-01-02 03:04:05" || len(histories[0].Items) != 1 || histories[0].Items[0].Title != "archived notebook" || histories[0].Items[0].Path != "/history/2026-01-02-030405-delete/box" {
+ t.Fatalf("notebook history sorting or metadata changed: %+v", histories)
+ }
+}
+
+func TestAPIContractDocHistoryLockedNotebook(t *testing.T) {
+ _, boxID := setupArchiveWorkspace(t)
+ previous := model.Conf
+ model.Conf = model.NewAppConf()
+ t.Cleanup(func() { model.Conf = previous })
+ engine := gin.New()
+ engine.POST("/api/history/getDocHistoryContent", getDocHistoryContent)
+ engine.POST("/api/history/rollbackDocHistory", rollbackDocHistory)
+ engine.POST("/api/history/rollbackAssetsHistory", rollbackAssetsHistory)
+ engine.POST("/api/history/rollbackAttributeViewHistory", rollbackAttributeViewHistory)
+ path := "history/2026-01-01-010203-update/" + boxID + "/20260101000000-abcdefg.sy"
+ for _, route := range []string{"getDocHistoryContent", "rollbackDocHistory", "rollbackAssetsHistory", "rollbackAttributeViewHistory"} {
+ endpoint := "/api/history/" + route
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", endpoint, strings.NewReader(`{"historyPath":" `+path+` ","highlight":false}`)))
+ requireAPIContract(t, "POST", endpoint, recorder)
+ var response struct {
+ Code int `json:"code"`
+ Msg string `json:"msg"`
+ Data json.RawMessage `json:"data"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != -1 || response.Msg != model.Conf.Language(314) || string(response.Data) != "null" {
+ t.Fatalf("locked history response changed: %s, %v", recorder.Body.String(), err)
+ }
+ }
+}
+
+func TestAPIContractHistoryCreationValidation(t *testing.T) {
+ engine := gin.New()
+ engine.POST("/api/history/createDocHistory", createDocHistory)
+ engine.POST("/api/history/createAssetHistory", createAssetHistory)
+ for _, path := range []string{"/api/history/createDocHistory", "/api/history/createAssetHistory"} {
+ for _, body := range []string{`{`, `{}`, `{"id":" ","path":" "}`, `{"id":false,"path":false}`} {
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", path, strings.NewReader(body)))
+ requireAPIContract(t, "POST", path, recorder)
+ var response struct {
+ Code int `json:"code"`
+ Data json.RawMessage `json:"data"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != -1 || string(response.Data) != "null" {
+ t.Fatalf("history validation changed: %s, %v", recorder.Body.String(), err)
+ }
+ }
+ }
+}
+
+func TestAPIContractDocVersionDiffConversion(t *testing.T) {
+ for _, diff := range []*model.DocVersionDiffResult{nil, {}, {
+ Left: &model.DocVersionDiffContent{ID: "left", RootID: "root", Title: "title", Content: "content"},
+ Right: &model.DocVersionDiffContent{ID: "right"},
+ Differences: []*model.DocVersionDifference{nil, {ID: "block", Statuses: []string{"modified", "moved"}}},
+ Large: true, Fallback: true, Message: "message", TitleModified: true,
+ }} {
+ expected, err := json.Marshal(diff)
+ if err != nil {
+ t.Fatal(err)
+ }
+ converted := docVersionDiffContract(diff)
+ actual, err := json.Marshal(converted)
+ if err != nil || string(expected) != string(actual) {
+ t.Fatalf("document diff changed: %s != %s, %v", expected, actual, err)
+ }
+ recorder := httptest.NewRecorder()
+ c, _ := gin.CreateTestContext(recorder)
+ c.JSON(200, apicontract.Success(converted))
+ requireAPIContract(t, "POST", "/api/history/diffDocVersions", recorder)
+ }
+}
+
+func TestAPIContractDocVersionDiffValidation(t *testing.T) {
+ engine := gin.New()
+ engine.POST("/api/history/diffDocVersions", diffDocVersions)
+ for _, entry := range []struct{ body, message string }{
+ {`{}`, "left document version is required"},
+ {`{"left":{},"right":false}`, "right document version is required"},
+ {`{"left":{},"right":{}}`, "Field [type] is required"},
+ } {
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/history/diffDocVersions", strings.NewReader(entry.body)))
+ requireAPIContract(t, "POST", "/api/history/diffDocVersions", recorder)
+ var response struct {
+ Code int `json:"code"`
+ Msg string `json:"msg"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != -1 || response.Msg != entry.message {
+ t.Fatalf("diff validation changed: %s, %v", recorder.Body.String(), err)
+ }
+ }
+}
diff --git a/kernel/api/history.go b/kernel/api/history.go
index 4cf033214d..9b7df65376 100644
--- a/kernel/api/history.go
+++ b/kernel/api/history.go
@@ -17,7 +17,6 @@
package api
import (
- "net/http"
"path/filepath"
"sort"
"time"
@@ -42,57 +41,46 @@ var searchHistory = contractHandler(apicontract.SearchHistory, func(c *gin.Conte
return apicontract.Success(apicontract.SearchHistoryData{Histories: histories, PageCount: pageCount, TotalCount: totalCount})
})
-func getHistoryItems(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var created, notebook, query, op string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("created", &created, true, true),
- util.BindJsonArg("notebook", &notebook, false, false),
- util.BindJsonArg("query", &query, false, false),
- util.BindJsonArg("op", &op, false, false),
- ) {
- return
- }
+var getHistoryItems = contractHandler(apicontract.GetHistoryItems, func(c *gin.Context, request apicontract.HistoryItemsRequest) apicontract.Response[apicontract.HistoryItemsData] {
typ := model.HistoryTypeDoc
- if nil != arg["type"] {
- typeVal, ok := util.ParseJsonArg[float64]("type", arg, ret, true, false)
- if !ok {
- return
- }
- typ = int(typeVal)
- }
- histories := model.FullTextSearchHistoryItems(created, query, notebook, op, typ)
- ret.Data = map[string]any{
- "items": histories,
+ if request.Type != nil {
+ typ = int(*request.Type)
}
-}
+ histories := model.FullTextSearchHistoryItems(request.Created, request.Query, request.Notebook, request.Op, typ)
+ return apicontract.Success(apicontract.HistoryItemsData{Items: historyItemContracts(histories)})
+})
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()
- defer c.JSON(http.StatusOK, ret)
-
+var getNotebookHistory = contractHandler(apicontract.GetNotebookHistory, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.NotebookHistoryData] {
histories, err := model.GetNotebookHistory()
if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ return apicontract.Failure[apicontract.NotebookHistoryData](-1, err.Error())
+ }
+ var result []*apicontract.History
+ if histories != nil {
+ result = make([]*apicontract.History, len(histories))
+ for i, history := range histories {
+ if history != nil {
+ result[i] = &apicontract.History{HCreated: history.HCreated, Items: historyItemContracts(history.Items)}
+ }
+ }
}
+ return apicontract.Success(apicontract.NotebookHistoryData{Histories: result})
+})
- ret.Data = map[string]any{
- "histories": histories,
+func historyItemContracts(items []*model.HistoryItem) []*apicontract.HistoryItem {
+ if items == nil {
+ return nil
}
+ result := make([]*apicontract.HistoryItem, len(items))
+ for i, item := range items {
+ result[i] = (*apicontract.HistoryItem)(item)
+ }
+ return result
}
var clearWorkspaceHistory = contractHandler(apicontract.ClearWorkspaceHistory, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
@@ -105,84 +93,30 @@ var clearWorkspaceHistory = contractHandler(apicontract.ClearWorkspaceHistory, f
return apicontract.Success(apicontract.Null{})
})
-func getDocHistoryContent(c *gin.Context) {
+var getDocHistoryContent = contractHandler(apicontract.GetDocHistoryContent, func(c *gin.Context, request apicontract.DocHistoryContentRequest) apicontract.Response[apicontract.DocHistoryContentData] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var historyPath, keyword string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("historyPath", &historyPath, true, true),
- util.BindJsonArg("k", &keyword, false, false),
- ) {
- return
- }
+ historyPath, keyword := request.HistoryPath, request.K
highlight := true
- if nil != arg["highlight"] {
- highlightVal, ok := util.ParseJsonArg[bool]("highlight", arg, ret, true, false)
- if !ok {
- return
- }
- highlight = highlightVal
+ if request.Highlight != nil {
+ highlight = *request.Highlight
}
if !holdHistoryRequest(c, historyPath, ret) {
- return
+ return contractFailure[apicontract.DocHistoryContentData](ret)
}
id, rootID, content, isLargeDoc, err := model.GetDocHistoryContent(historyPath, keyword, highlight)
if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
- }
-
- ret.Data = map[string]any{
- "id": id,
- "rootID": rootID,
- "content": content,
- "isLargeDoc": isLargeDoc,
- }
-}
-
-func diffDocVersions(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ return apicontract.Failure[apicontract.DocHistoryContentData](-1, err.Error())
}
+ return apicontract.Success(apicontract.DocHistoryContentData{ID: id, RootID: rootID, Content: content, IsLargeDoc: isLargeDoc})
+})
- leftArg, ok := arg["left"].(map[string]interface{})
- if !ok {
- ret.Code = -1
- ret.Msg = "left document version is required"
- return
- }
- rightArg, ok := arg["right"].(map[string]interface{})
- if !ok {
- ret.Code = -1
- ret.Msg = "right document version is required"
- return
- }
- left, ok := parseDocVersionRef(leftArg, ret)
- if !ok {
- return
- }
- right, ok := parseDocVersionRef(rightArg, ret)
- if !ok {
- return
- }
+var diffDocVersions = contractHandler(apicontract.DiffDocVersions, func(c *gin.Context, request apicontract.DiffDocVersionsRequest) apicontract.Response[*apicontract.DocVersionDiffResult] {
+ left, right := (*model.DocVersionRef)(&request.Left), (*model.DocVersionRef)(&request.Right)
boxIDs := map[string]struct{}{}
for _, ref := range []*model.DocVersionRef{left, right} {
boxID, resolveErr := model.ResolveDocVersionBoxID(ref)
if resolveErr != nil {
- ret.Code = -1
- ret.Msg = resolveErr.Error()
- return
+ return apicontract.Failure[*apicontract.DocVersionDiffResult](-1, resolveErr.Error())
}
if boxID != "" {
boxIDs[boxID] = struct{}{}
@@ -195,128 +129,56 @@ func diffDocVersions(c *gin.Context) {
sort.Strings(sortedBoxIDs)
for _, boxID := range sortedBoxIDs {
if err := holdEncryptedBoxRequest(c, boxID); err != nil {
- ret.Code = -1
- ret.Msg = model.Conf.Language(314)
- return
+ return apicontract.Failure[*apicontract.DocVersionDiffResult](-1, model.Conf.Language(314))
}
}
diff, err := model.DiffDocVersions(left, right)
if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
- }
- ret.Data = diff
-}
-
-func parseDocVersionRef(arg map[string]interface{}, ret *gulu.Result) (ref *model.DocVersionRef, ok bool) {
- var typ, id, path, snapshot string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("type", &typ, true, true),
- util.BindJsonArg("id", &id, false, false),
- util.BindJsonArg("path", &path, false, false),
- util.BindJsonArg("snapshot", &snapshot, false, false),
- ) {
- return nil, false
+ return apicontract.Failure[*apicontract.DocVersionDiffResult](-1, err.Error())
}
- return &model.DocVersionRef{Type: typ, ID: id, Path: path, Snapshot: snapshot}, true
-}
+ return apicontract.Success(docVersionDiffContract(diff))
+})
-func rollbackDocHistory(c *gin.Context) {
+var rollbackDocHistory = contractHandler(apicontract.RollbackDocHistory, func(c *gin.Context, request apicontract.HistoryPathRequest) apicontract.Response[apicontract.Null] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var historyPath string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("historyPath", &historyPath, true, true),
- ) {
- return
- }
- if !holdHistoryRequest(c, historyPath, ret) {
- return
+ if !holdHistoryRequest(c, request.HistoryPath, ret) {
+ return contractFailure[apicontract.Null](ret)
}
- err := model.RollbackDocHistory(historyPath)
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ if err := model.RollbackDocHistory(request.HistoryPath); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
-func rollbackAssetsHistory(c *gin.Context) {
+var rollbackAssetsHistory = contractHandler(apicontract.RollbackAssetsHistory, func(c *gin.Context, request apicontract.HistoryPathRequest) apicontract.Response[apicontract.Null] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var historyPath string
- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("historyPath", &historyPath, true, true)) {
- return
- }
- if !holdHistoryRequest(c, historyPath, ret) {
- return
- }
- err := model.RollbackAssetsHistory(historyPath)
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ if !holdHistoryRequest(c, request.HistoryPath, ret) {
+ return contractFailure[apicontract.Null](ret)
}
-}
-
-func rollbackNotebookHistory(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
+ if err := model.RollbackAssetsHistory(request.HistoryPath); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
+ return apicontract.Success(apicontract.Null{})
+})
- var historyPath string
- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("historyPath", &historyPath, true, true)) {
- return
- }
- err := model.RollbackNotebookHistory(historyPath)
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+var rollbackNotebookHistory = contractHandler(apicontract.RollbackNotebookHistory, func(c *gin.Context, request apicontract.HistoryPathRequest) apicontract.Response[apicontract.Null] {
+ if err := model.RollbackNotebookHistory(request.HistoryPath); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
-func rollbackAttributeViewHistory(c *gin.Context) {
+var rollbackAttributeViewHistory = contractHandler(apicontract.RollbackAttributeViewHistory, func(c *gin.Context, request apicontract.HistoryPathRequest) apicontract.Response[apicontract.Null] {
ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var historyPath string
- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("historyPath", &historyPath, true, true)) {
- return
- }
- if !holdHistoryRequest(c, historyPath, ret) {
- return
+ if !holdHistoryRequest(c, request.HistoryPath, ret) {
+ return contractFailure[apicontract.Null](ret)
}
- err := model.RollbackAttributeViewHistory(historyPath)
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ if err := model.RollbackAttributeViewHistory(request.HistoryPath); err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
-}
+ return apicontract.Success(apicontract.Null{})
+})
func holdHistoryRequest(c *gin.Context, historyPath string, ret *gulu.Result) bool {
absolutePath := filepath.Join(util.WorkspaceDir, historyPath)
@@ -329,50 +191,33 @@ func holdHistoryRequest(c *gin.Context, historyPath string, ret *gulu.Result) bo
return true
}
-func createDocHistory(c *gin.Context) {
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
-
- arg, ok := util.JsonArg(c, ret)
- if !ok {
- return
- }
-
- var id string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("id", &id, true, true),
- ) {
- return
- }
-
- err := model.CreateDocHistory(id)
+var createDocHistory = contractHandler(apicontract.CreateDocHistory, func(c *gin.Context, request apicontract.CreateDocHistoryRequest) apicontract.Response[apicontract.Null] {
+ err := model.CreateDocHistory(request.ID)
if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
-}
-
-func createAssetHistory(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 createAssetHistory = contractHandler(apicontract.CreateAssetHistory, func(c *gin.Context, request apicontract.CreateAssetHistoryRequest) apicontract.Response[apicontract.Null] {
+ err := model.CreateAssetHistory(request.Path)
+ if err != nil {
+ return apicontract.Failure[apicontract.Null](-1, err.Error())
}
+ return apicontract.Success(apicontract.Null{})
+})
- var assetPath string
- if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("path", &assetPath, true, true),
- ) {
- return
+func docVersionDiffContract(diff *model.DocVersionDiffResult) *apicontract.DocVersionDiffResult {
+ if diff == nil {
+ return nil
}
-
- err := model.CreateAssetHistory(assetPath)
- if err != nil {
- ret.Code = -1
- ret.Msg = err.Error()
- return
+ result := &apicontract.DocVersionDiffResult{Left: (*apicontract.DocVersionDiffContent)(diff.Left), Right: (*apicontract.DocVersionDiffContent)(diff.Right),
+ Large: diff.Large, Fallback: diff.Fallback, Message: diff.Message, TitleModified: diff.TitleModified}
+ if diff.Differences != nil {
+ result.Differences = make([]*apicontract.DocVersionDifference, len(diff.Differences))
+ for i, difference := range diff.Differences {
+ result.Differences[i] = (*apicontract.DocVersionDifference)(difference)
+ }
}
+ return result
}
diff --git a/kernel/api/history_test.go b/kernel/api/history_test.go
index de2584913d..16b5ef8d02 100644
--- a/kernel/api/history_test.go
+++ b/kernel/api/history_test.go
@@ -9,21 +9,19 @@
package api
import (
+ "strings"
"testing"
- "github.com/88250/gulu"
+ "github.com/siyuan-note/siyuan/kernel/apicontract"
)
func TestParseDocVersionRefIncludesSnapshot(t *testing.T) {
const snapshot = "6b7f54c510e8de12be6e446494987c846f13cd0d"
- ref, ok := parseDocVersionRef(map[string]interface{}{
- "type": "snapshot",
- "id": "1c2971f02672edbc0d2ec6160df7c9c9a18d7402",
- "snapshot": snapshot,
- }, gulu.Ret.NewResult())
- if !ok {
+ request, err := apicontract.DiffDocVersions.Decode(strings.NewReader(`{"left":{"type":"snapshot","id":"1c2971f02672edbc0d2ec6160df7c9c9a18d7402","snapshot":"` + snapshot + `"},"right":{"type":"current"}}`))
+ if err != nil {
t.Fatal("expected document version reference parsing to succeed")
}
+ ref := request.Left
if snapshot != ref.Snapshot {
t.Fatalf("expected snapshot [%s], got [%s]", snapshot, ref.Snapshot)
}
diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.go
index 743477630e..11e9594dfd 100644
--- a/kernel/apicontract/contracts.go
+++ b/kernel/apicontract/contracts.go
@@ -518,3 +518,14 @@ var ImportZipMd = define[ImportZipMarkdownRequest, Null]("importZipMd", "/api/im
var ImportSY = define[ImportSYRequest, Null]("importSY", "/api/import/importSY", MultipartBody, ResponseOptions{}, "POST")
var ImportSYNotebook = define[ImportDataRequest, ImportNotebookData]("importSYNotebook", "/api/import/importSYNotebook", MultipartBody, ResponseOptions{}, "POST")
var ImportSYAuto = define[ImportSYRequest, ImportAutoData]("importSYAuto", "/api/import/importSYAuto", MultipartBody, ResponseOptions{DataOnError: true}, "POST")
+
+var GetHistoryItems = define[HistoryItemsRequest, HistoryItemsData]("getHistoryItems", "/api/history/getHistoryItems", JSONBody, ResponseOptions{}, "POST")
+var GetNotebookHistory = define[EmptyRequest, NotebookHistoryData]("getNotebookHistory", "/api/history/getNotebookHistory", NoBody, ResponseOptions{}, "POST")
+var GetDocHistoryContent = define[DocHistoryContentRequest, DocHistoryContentData]("getDocHistoryContent", "/api/history/getDocHistoryContent", JSONBody, ResponseOptions{}, "POST")
+var CreateDocHistory = define[CreateDocHistoryRequest, Null]("createDocHistory", "/api/history/createDocHistory", JSONBody, ResponseOptions{}, "POST")
+var CreateAssetHistory = define[CreateAssetHistoryRequest, Null]("createAssetHistory", "/api/history/createAssetHistory", JSONBody, ResponseOptions{}, "POST")
+var RollbackDocHistory = define[HistoryPathRequest, Null]("rollbackDocHistory", "/api/history/rollbackDocHistory", JSONBody, ResponseOptions{}, "POST")
+var RollbackAssetsHistory = define[HistoryPathRequest, Null]("rollbackAssetsHistory", "/api/history/rollbackAssetsHistory", JSONBody, ResponseOptions{}, "POST")
+var RollbackNotebookHistory = define[HistoryPathRequest, Null]("rollbackNotebookHistory", "/api/history/rollbackNotebookHistory", JSONBody, ResponseOptions{}, "POST")
+var RollbackAttributeViewHistory = define[HistoryPathRequest, Null]("rollbackAttributeViewHistory", "/api/history/rollbackAttributeViewHistory", JSONBody, ResponseOptions{}, "POST")
+var DiffDocVersions = define[DiffDocVersionsRequest, *DocVersionDiffResult]("diffDocVersions", "/api/history/diffDocVersions", JSONBody, ResponseOptions{}, "POST")
diff --git a/kernel/apicontract/history.go b/kernel/apicontract/history.go
new file mode 100644
index 0000000000..52424c2796
--- /dev/null
+++ b/kernel/apicontract/history.go
@@ -0,0 +1,55 @@
+package apicontract
+
+type HistoryPathRequest struct {
+ HistoryPath string `json:"historyPath" api:"trim"`
+}
+
+type CreateDocHistoryRequest struct {
+ ID string `json:"id" api:"trim"`
+}
+
+type CreateAssetHistoryRequest struct {
+ Path string `json:"path" api:"trim"`
+}
+
+type DocHistoryContentRequest struct {
+ HistoryPath string `json:"historyPath" api:"trim"`
+ K string `json:"k" api:"optional,nullable"`
+ Highlight *bool `json:"highlight" api:"optional"`
+}
+
+type DocHistoryContentData struct {
+ ID string `json:"id"`
+ RootID string `json:"rootID"`
+ Content string `json:"content"`
+ IsLargeDoc bool `json:"isLargeDoc"`
+}
+
+type HistoryItemsRequest struct {
+ Created string `json:"created" api:"trim"`
+ Notebook string `json:"notebook" api:"optional,nullable"`
+ Query string `json:"query" api:"optional,nullable"`
+ Op string `json:"op" api:"optional,nullable"`
+ Type *float64 `json:"type" api:"optional"`
+}
+
+type HistoryItem struct {
+ ID string `json:"id"`
+ Title string `json:"title"`
+ Path string `json:"path"`
+ Op string `json:"op"`
+ Notebook string `json:"notebook"`
+}
+
+type History struct {
+ HCreated string `json:"hCreated"`
+ Items []*HistoryItem `json:"items"`
+}
+
+type HistoryItemsData struct {
+ Items []*HistoryItem `json:"items"`
+}
+
+type NotebookHistoryData struct {
+ Histories []*History `json:"histories"`
+}
diff --git a/kernel/apicontract/history_diff.go b/kernel/apicontract/history_diff.go
new file mode 100644
index 0000000000..a61bdc2cac
--- /dev/null
+++ b/kernel/apicontract/history_diff.go
@@ -0,0 +1,81 @@
+package apicontract
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+)
+
+type DocVersionRef struct {
+ Type string `json:"type" api:"trim"`
+ ID string `json:"id" api:"optional,nullable"`
+ Path string `json:"path" api:"optional,nullable"`
+ Snapshot string `json:"snapshot" api:"optional,nullable"`
+}
+
+type DiffDocVersionsRequest struct {
+ Left DocVersionRef `json:"left"`
+ Right DocVersionRef `json:"right"`
+}
+
+type DocVersionDiffContent struct {
+ ID string `json:"id"`
+ RootID string `json:"rootID"`
+ Title string `json:"title"`
+ Content string `json:"content"`
+}
+
+type DocVersionDifference struct {
+ ID string `json:"id"`
+ Statuses []string `json:"statuses"`
+}
+
+type DocVersionDiffResult struct {
+ Left *DocVersionDiffContent `json:"left"`
+ Right *DocVersionDiffContent `json:"right"`
+ Differences []*DocVersionDifference `json:"differences"`
+ Large bool `json:"large"`
+ Fallback bool `json:"fallback"`
+ Message string `json:"message"`
+ TitleModified bool `json:"titleModified"`
+}
+
+func init() {
+ DiffDocVersions.decodeRequest = func(reader io.Reader) (request DiffDocVersionsRequest, err error) {
+ fields, err := blockRequestFields(reader, "/api/history/diffDocVersions")
+ if err != nil {
+ return request, err
+ }
+ var left, right map[string]json.RawMessage
+ if json.Unmarshal(fields["left"], &left) != nil || left == nil {
+ return request, fmt.Errorf("left document version is required")
+ }
+ if json.Unmarshal(fields["right"], &right) != nil || right == nil {
+ return request, fmt.Errorf("right document version is required")
+ }
+ if request.Left, err = decodeDocVersionRef(left); err != nil {
+ return request, err
+ }
+ request.Right, err = decodeDocVersionRef(right)
+ return request, err
+ }
+}
+
+func decodeDocVersionRef(fields map[string]json.RawMessage) (request DocVersionRef, err error) {
+ if request.Type, err = legacyField[string](fields, "type", "String", true); err != nil {
+ return request, err
+ }
+ request.Type = strings.TrimSpace(request.Type)
+ if request.Type == "" {
+ return request, fmt.Errorf("Field [type] must not be empty")
+ }
+ if request.ID, err = legacyField[string](fields, "id", "String", false); err != nil {
+ return request, err
+ }
+ if request.Path, err = legacyField[string](fields, "path", "String", false); err != nil {
+ return request, err
+ }
+ request.Snapshot, err = legacyField[string](fields, "snapshot", "String", false)
+ return request, err
+}
diff --git a/kernel/apicontract/history_test.go b/kernel/apicontract/history_test.go
new file mode 100644
index 0000000000..1903578d78
--- /dev/null
+++ b/kernel/apicontract/history_test.go
@@ -0,0 +1,83 @@
+package apicontract
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestHistoryItemsRequestCompatibility(t *testing.T) {
+ request, err := GetHistoryItems.Decode(strings.NewReader(`{"created":" time ","query":" query ","notebook":null,"op":" op ","type":1.9}`))
+ if err != nil || request.Created != "time" || request.Query != " query " || request.Notebook != "" || request.Op != " op " || request.Type == nil || *request.Type != 1.9 {
+ t.Fatalf("history input changed: %+v, %v", request, err)
+ }
+ request, err = GetHistoryItems.Decode(strings.NewReader(`{"created":"time","type":null}`))
+ if err != nil || request.Type != nil {
+ t.Fatalf("default history type changed: %+v, %v", request, err)
+ }
+ for _, body := range []string{`{}`, `{"created":" "}`, `{"created":"time","type":"1"}`, `{"created":"time","query":false}`} {
+ if _, err := GetHistoryItems.Decode(strings.NewReader(body)); err == nil {
+ t.Fatalf("invalid history input accepted: %s", body)
+ }
+ }
+}
+
+func TestDocHistoryContentRequestCompatibility(t *testing.T) {
+ for _, field := range []string{"", `,"highlight":null`, `,"highlight":false`, `,"highlight":true`} {
+ request, err := GetDocHistoryContent.Decode(strings.NewReader(`{"historyPath":" path ","k":" keyword "` + field + `}`))
+ if err != nil || request.HistoryPath != "path" || request.K != " keyword " {
+ t.Fatalf("history content input changed: %+v, %v", request, err)
+ }
+ if field == "" || strings.Contains(field, "null") {
+ if request.Highlight != nil {
+ t.Fatal("missing or null highlight must retain the handler default")
+ }
+ } else if request.Highlight == nil || *request.Highlight != strings.Contains(field, "true") {
+ t.Fatalf("explicit highlight changed: %+v", request)
+ }
+ }
+ if _, err := GetDocHistoryContent.Decode(strings.NewReader(`{"historyPath":"path","highlight":"true"}`)); err == nil {
+ t.Fatal("invalid highlight accepted")
+ }
+}
+
+func TestCreateHistoryRequestTrimming(t *testing.T) {
+ doc, err := CreateDocHistory.Decode(strings.NewReader(`{"id":" id "}`))
+ if err != nil || doc.ID != "id" {
+ t.Fatalf("document ID trimming changed: %+v, %v", doc, err)
+ }
+ asset, err := CreateAssetHistory.Decode(strings.NewReader(`{"path":" assets/file "}`))
+ if err != nil || asset.Path != "assets/file" {
+ t.Fatalf("asset path trimming changed: %+v, %v", asset, err)
+ }
+}
+
+func TestRollbackHistoryRequestCompatibility(t *testing.T) {
+ for _, endpoint := range []Endpoint[HistoryPathRequest, Null]{RollbackDocHistory, RollbackAssetsHistory, RollbackNotebookHistory, RollbackAttributeViewHistory} {
+ request, err := endpoint.Decode(strings.NewReader(`{"historyPath":" history/path "}`))
+ if err != nil || request.HistoryPath != "history/path" {
+ t.Fatalf("history path trimming changed: %+v, %v", request, err)
+ }
+ for _, body := range []string{`{}`, `{"historyPath":null}`, `{"historyPath":" "}`, `{"historyPath":false}`} {
+ if _, err := endpoint.Decode(strings.NewReader(body)); err == nil {
+ t.Fatalf("invalid rollback request accepted: %s", body)
+ }
+ }
+ }
+}
+
+func TestDocVersionDecodeCompatibility(t *testing.T) {
+ for _, entry := range []struct{ body, message string }{
+ {`{}`, "left document version is required"},
+ {`{"left":{},"right":null}`, "right document version is required"},
+ {`{"left":{},"right":{}}`, "Field [type] is required"},
+ {`{"left":{"type":" "},"right":{"type":"current"}}`, "Field [type] must not be empty"},
+ } {
+ if _, err := DiffDocVersions.Decode(strings.NewReader(entry.body)); err == nil || err.Error() != entry.message {
+ t.Fatalf("version validation order changed: %s, %v", entry.body, err)
+ }
+ }
+ request, err := DiffDocVersions.Decode(strings.NewReader(`{"left":{"type":" history ","id":" id ","path":" path ","snapshot":null},"right":{"type":"current"}}`))
+ if err != nil || request.Left.Type != "history" || request.Left.ID != " id " || request.Left.Path != " path " || request.Left.Snapshot != "" {
+ t.Fatalf("version input changed: %+v, %v", request, err)
+ }
+}
diff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.json
index 9d4b96b8f5..d616fa7cea 100644
--- a/kernel/apicontract/legacy_routes.json
+++ b/kernel/apicontract/legacy_routes.json
@@ -222,16 +222,6 @@
{"method":"POST","path":"/api/filetree/setPublishAccess","handler":"setPublishAccess"},
{"method":"POST","path":"/api/filetree/setSort","handler":"setSort"},
{"method":"POST","path":"/api/filetree/upsertIndexes","handler":"upsertIndexes"},
- {"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/rollbackAssetsHistory","handler":"rollbackAssetsHistory"},
- {"method":"POST","path":"/api/history/rollbackAttributeViewHistory","handler":"rollbackAttributeViewHistory"},
- {"method":"POST","path":"/api/history/rollbackDocHistory","handler":"rollbackDocHistory"},
- {"method":"POST","path":"/api/history/rollbackNotebookHistory","handler":"rollbackNotebookHistory"},
{"method":"POST","path":"/api/network/forwardProxy","handler":"forwardProxy"},
{"method":"POST","path":"/api/plugin/getLoadedPlugin","handler":"getLoadedPlugin"},
{"method":"POST","path":"/api/plugin/listLoadedPlugins","handler":"listLoadedPlugins"},
diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.json
index c5409dbe79..9a06fa2517 100644
--- a/kernel/apicontract/schema.json
+++ b/kernel/apicontract/schema.json
@@ -2685,6 +2685,30 @@
],
"additionalProperties": false
},
+ "CreateAssetHistoryRequestInput": {
+ "type": "object",
+ "properties": {
+ "path": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "path"
+ ],
+ "additionalProperties": false
+ },
+ "CreateDocHistoryRequestInput": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "id"
+ ],
+ "additionalProperties": false
+ },
"CreateEncryptedNotebookRequestInput": {
"type": "object",
"properties": {
@@ -3680,6 +3704,22 @@
],
"additionalProperties": false
},
+ "DiffDocVersionsRequestInput": {
+ "type": "object",
+ "properties": {
+ "left": {
+ "$ref": "#/$defs/DocVersionRefInput"
+ },
+ "right": {
+ "$ref": "#/$defs/DocVersionRefInput"
+ }
+ },
+ "required": [
+ "left",
+ "right"
+ ],
+ "additionalProperties": false
+ },
"DirectoryEntry": {
"type": "object",
"properties": {
@@ -3813,6 +3853,62 @@
},
"additionalProperties": false
},
+ "DocHistoryContentData": {
+ "type": "object",
+ "properties": {
+ "content": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "isLargeDoc": {
+ "type": "boolean"
+ },
+ "rootID": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "content",
+ "id",
+ "isLargeDoc",
+ "rootID"
+ ],
+ "additionalProperties": false
+ },
+ "DocHistoryContentRequestInput": {
+ "type": "object",
+ "properties": {
+ "highlight": {
+ "anyOf": [
+ {
+ "type": "boolean"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "historyPath": {
+ "type": "string"
+ },
+ "k": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "historyPath"
+ ],
+ "additionalProperties": false
+ },
"DocInfo": {
"type": "object",
"properties": {
@@ -3906,6 +4002,165 @@
],
"additionalProperties": false
},
+ "DocVersionDiffContent": {
+ "type": "object",
+ "properties": {
+ "content": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ },
+ "rootID": {
+ "type": "string"
+ },
+ "title": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "content",
+ "id",
+ "rootID",
+ "title"
+ ],
+ "additionalProperties": false
+ },
+ "DocVersionDiffResult": {
+ "type": "object",
+ "properties": {
+ "differences": {
+ "anyOf": [
+ {
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/DocVersionDifference"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "fallback": {
+ "type": "boolean"
+ },
+ "large": {
+ "type": "boolean"
+ },
+ "left": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/DocVersionDiffContent"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "message": {
+ "type": "string"
+ },
+ "right": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/DocVersionDiffContent"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "titleModified": {
+ "type": "boolean"
+ }
+ },
+ "required": [
+ "differences",
+ "fallback",
+ "large",
+ "left",
+ "message",
+ "right",
+ "titleModified"
+ ],
+ "additionalProperties": false
+ },
+ "DocVersionDifference": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "statuses": {
+ "anyOf": [
+ {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "id",
+ "statuses"
+ ],
+ "additionalProperties": false
+ },
+ "DocVersionRefInput": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "path": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "snapshot": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "type": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "type"
+ ],
+ "additionalProperties": false
+ },
"DocsInfoRequestInput": {
"type": "object",
"properties": {
@@ -5070,46 +5325,200 @@
},
"additionalProperties": false
},
- "ImportAutoDocument": {
+ "History": {
"type": "object",
"properties": {
- "token": {
+ "hCreated": {
"type": "string"
},
- "type": {
- "type": "string",
- "enum": [
- "document"
- ]
- }
- },
- "required": [
- "type"
- ],
- "additionalProperties": false
- },
- "ImportAutoNotebook": {
- "type": "object",
- "properties": {
- "notebook": {
+ "items": {
"anyOf": [
{
- "$ref": "#/$defs/Notebook"
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/HistoryItem"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
},
{
"type": "null"
}
]
- },
- "type": {
- "type": "string",
- "enum": [
- "notebook"
- ]
}
},
"required": [
- "notebook",
+ "hCreated",
+ "items"
+ ],
+ "additionalProperties": false
+ },
+ "HistoryItem": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "notebook": {
+ "type": "string"
+ },
+ "op": {
+ "type": "string"
+ },
+ "path": {
+ "type": "string"
+ },
+ "title": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "id",
+ "notebook",
+ "op",
+ "path",
+ "title"
+ ],
+ "additionalProperties": false
+ },
+ "HistoryItemsData": {
+ "type": "object",
+ "properties": {
+ "items": {
+ "anyOf": [
+ {
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/HistoryItem"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "items"
+ ],
+ "additionalProperties": false
+ },
+ "HistoryItemsRequestInput": {
+ "type": "object",
+ "properties": {
+ "created": {
+ "type": "string"
+ },
+ "notebook": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "op": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "query": {
+ "anyOf": [
+ {
+ "type": "string"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "type": {
+ "anyOf": [
+ {
+ "type": "number"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "created"
+ ],
+ "additionalProperties": false
+ },
+ "HistoryPathRequestInput": {
+ "type": "object",
+ "properties": {
+ "historyPath": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "historyPath"
+ ],
+ "additionalProperties": false
+ },
+ "ImportAutoDocument": {
+ "type": "object",
+ "properties": {
+ "token": {
+ "type": "string"
+ },
+ "type": {
+ "type": "string",
+ "enum": [
+ "document"
+ ]
+ }
+ },
+ "required": [
+ "type"
+ ],
+ "additionalProperties": false
+ },
+ "ImportAutoNotebook": {
+ "type": "object",
+ "properties": {
+ "notebook": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/Notebook"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "type": {
+ "type": "string",
+ "enum": [
+ "notebook"
+ ]
+ }
+ },
+ "required": [
+ "notebook",
"type"
],
"additionalProperties": false
@@ -7019,6 +7428,35 @@
},
"additionalProperties": false
},
+ "NotebookHistoryData": {
+ "type": "object",
+ "properties": {
+ "histories": {
+ "anyOf": [
+ {
+ "type": "array",
+ "items": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/History"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ {
+ "type": "null"
+ }
+ ]
+ }
+ },
+ "required": [
+ "histories"
+ ],
+ "additionalProperties": false
+ },
"NotebookIDRequestInput": {
"type": "object",
"properties": {
@@ -19330,11 +19768,768 @@
},
{
"method": "POST",
- "path": "/api/history/reindexHistory",
- "handler": "reindexHistory",
- "body": "none",
+ "path": "/api/history/createAssetHistory",
+ "handler": "createAssetHistory",
+ "body": "json",
"request": {
- "$ref": "#/$defs/EmptyRequestInput"
+ "$ref": "#/$defs/CreateAssetHistoryRequestInput"
+ },
+ "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/createDocHistory",
+ "handler": "createDocHistory",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/CreateDocHistoryRequestInput"
+ },
+ "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/diffDocVersions",
+ "handler": "diffDocVersions",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/DiffDocVersionsRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/DocVersionDiffResult"
+ },
+ {
+ "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/getDocHistoryContent",
+ "handler": "getDocHistoryContent",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/DocHistoryContentRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/DocHistoryContentData"
+ },
+ "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/getHistoryItems",
+ "handler": "getHistoryItems",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/HistoryItemsRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/HistoryItemsData"
+ },
+ "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/getNotebookHistory",
+ "handler": "getNotebookHistory",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/NotebookHistoryData"
+ },
+ "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/rollbackAssetsHistory",
+ "handler": "rollbackAssetsHistory",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/HistoryPathRequestInput"
+ },
+ "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/rollbackAttributeViewHistory",
+ "handler": "rollbackAttributeViewHistory",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/HistoryPathRequestInput"
+ },
+ "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/rollbackDocHistory",
+ "handler": "rollbackDocHistory",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/HistoryPathRequestInput"
+ },
+ "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/rollbackNotebookHistory",
+ "handler": "rollbackNotebookHistory",
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/HistoryPathRequestInput"
},
"response": {
"anyOf": [