Skip to content

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

:art: Supports cleaning up unreferenced databases https://github.com/siyuan-note/siyuan/issues/11569

Danielaa1893e3deb7
diff --git a/app/src/history/history.ts b/app/src/history/history.ts
index c5850ec926..fc9bb4b965 100644
--- a/app/src/history/history.ts
+++ b/app/src/history/history.ts
@@ -580,9 +580,7 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
historyPath: target.parentElement.getAttribute("data-path")
});
} else if (dataType === "av") {
- // TODO
- fetchPost("/api/history/rollbackDocHistory", {
- notebook: target.parentElement.getAttribute("data-notebook-id"),
+ fetchPost("/api/history/rollbackAttributeViewHistory", {
historyPath: target.parentElement.getAttribute("data-path")
});
} else if (dataType === "notebook") {
diff --git a/kernel/api/history.go b/kernel/api/history.go
index 29014224ec..a3f419258a 100644
--- a/kernel/api/history.go
+++ b/kernel/api/history.go
@@ -222,3 +222,21 @@ func rollbackNotebookHistory(c *gin.Context) {
return
}
}
+
+func rollbackAttributeViewHistory(c *gin.Context) {
+ ret := gulu.Ret.NewResult()
+ defer c.JSON(http.StatusOK, ret)
+
+ arg, ok := util.JsonArg(c, ret)
+ if !ok {
+ return
+ }
+
+ historyPath := arg["historyPath"].(string)
+ err := model.RollbackAttributeViewHistory(historyPath)
+ if err != nil {
+ ret.Code = -1
+ ret.Msg = err.Error()
+ return
+ }
+}
diff --git a/kernel/api/router.go b/kernel/api/router.go
index af0ba3bfb9..e52d8e7b36 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -146,6 +146,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/format/netImg2LocalAssets", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, netImg2LocalAssets)
ginServer.Handle("POST", "/api/format/netAssets2LocalAssets", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, netAssets2LocalAssets)
+ ginServer.Handle("POST", "/api/history/rollbackAttributeViewHistory", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, rollbackAttributeViewHistory)
ginServer.Handle("POST", "/api/history/getNotebookHistory", model.CheckAuth, model.CheckAdminRole, getNotebookHistory)
ginServer.Handle("POST", "/api/history/rollbackNotebookHistory", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, rollbackNotebookHistory)
ginServer.Handle("POST", "/api/history/rollbackAssetsHistory", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, rollbackAssetsHistory)
diff --git a/kernel/model/history.go b/kernel/model/history.go
index bb67ce2d24..e259bf2638 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -426,6 +426,24 @@ func RollbackNotebookHistory(historyPath string) (err error) {
return nil
}
+func RollbackAttributeViewHistory(historyPath string) (err error) {
+ if !gulu.File.IsExist(historyPath) {
+ logging.LogWarnf("av history [%s] not exist", historyPath)
+ return
+ }
+
+ from := historyPath
+ to := filepath.Join(util.DataDir, "storage", "av", filepath.Base(historyPath))
+
+ if err = filelock.CopyNewtimes(from, to); err != nil {
+ logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
+ return
+ }
+ IncSync()
+ util.PushMsg(Conf.Language(102), 3000)
+ return nil
+}
+
type History struct {
HCreated string `json:"hCreated"`
Items []*HistoryItem `json:"items"`