Skip to content

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

:technologist: Remove the `notebook` parameter from the API `/api/history/rollbackDocHistory` endpoint https://github.com/siyuan-note/siyuan/issues/17411

Daniel9d4c65c96b96
diff --git a/app/src/history/doc.ts b/app/src/history/doc.ts
index bb05619365..f3a6e80e8d 100644
--- a/app/src/history/doc.ts
+++ b/app/src/history/doc.ts
@@ -150,7 +150,6 @@ export const openDocHistory = (options: {
.replace("${time}", target.previousElementSibling.previousElementSibling.textContent.trim());
confirmDialog("⚠️ " + window.siyuan.languages.rollback, confirmTip, () => {
fetchPost("/api/history/rollbackDocHistory", {
- notebook: options.notebookId,
historyPath: dataPath
});
});
diff --git a/app/src/history/history.ts b/app/src/history/history.ts
index e0e49615a6..23e69d2400 100644
--- a/app/src/history/history.ts
+++ b/app/src/history/history.ts
@@ -581,7 +581,6 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
});
} else if (dataType === "doc") {
fetchPost("/api/history/rollbackDocHistory", {
- notebook: target.parentElement.getAttribute("data-notebook-id"),
historyPath: target.parentElement.getAttribute("data-path")
});
} else if (dataType === "av") {
diff --git a/kernel/api/history.go b/kernel/api/history.go
index 2109efb7c0..6f3aadbdb1 100644
--- a/kernel/api/history.go
+++ b/kernel/api/history.go
@@ -185,23 +185,18 @@ func rollbackDocHistory(c *gin.Context) {
return
}
- var notebook, historyPath string
+ var historyPath string
if !util.ParseJsonArgs(arg, ret,
- util.BindJsonArg("notebook", &notebook, true, true),
util.BindJsonArg("historyPath", &historyPath, true, true),
) {
return
}
- err := model.RollbackDocHistory(notebook, historyPath)
+ err := model.RollbackDocHistory(historyPath)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
return
}
-
- ret.Data = map[string]any{
- "box": notebook,
- }
}
func rollbackAssetsHistory(c *gin.Context) {
diff --git a/kernel/model/history.go b/kernel/model/history.go
index 2767383f8d..6906febeac 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -227,7 +227,7 @@ func GetDocHistoryContent(historyPath, keyword string, highlight bool) (id, root
return
}
-func RollbackDocHistory(boxID, historyPath string) (err error) {
+func RollbackDocHistory(historyPath string) (err error) {
if !gulu.File.IsExist(historyPath) {
logging.LogWarnf("doc history [%s] not exist", historyPath)
return
@@ -235,6 +235,16 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
FlushTxQueue()
+ relPath := strings.TrimPrefix(historyPath, util.HistoryDir)
+ relPath = strings.TrimPrefix(relPath, string(os.PathSeparator))
+ relPath = filepath.ToSlash(relPath)
+ parts := strings.SplitN(relPath, "/", 3)
+ if len(parts) < 3 {
+ logging.LogWarnf("invalid history path [%s]", historyPath)
+ return
+ }
+ boxID := parts[1]
+
box, needResetTree, err := getRollbackBox(boxID)
if err != nil {
logging.LogErrorf("get rollback box [%s] failed: %s", boxID, err)
@@ -258,11 +268,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
var avIDs []string
tree, _ := loadTree(srcPath, util.NewLute())
if nil != tree {
- historyDir := strings.TrimPrefix(historyPath, util.HistoryDir+string(os.PathSeparator))
- if strings.Contains(historyDir, string(os.PathSeparator)) {
- historyDir = historyDir[:strings.Index(historyDir, string(os.PathSeparator))]
- }
- historyDir = filepath.Join(util.HistoryDir, historyDir)
+ historyDir := filepath.Join(util.HistoryDir, parts[0])
avNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)
for _, avNode := range avNodes {