An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 数据历史文档中支持操作类型过滤 https://github.com/siyuan-note/siyuan/issues/5754
Liang Ding05c0de492231
diff --git a/kernel/api/history.go b/kernel/api/history.goindex f3ede87148..3d15ff5cda 100644--- a/kernel/api/history.go+++ b/kernel/api/history.go@@ -35,6 +35,15 @@ func searchHistory(c *gin.Context) {return}+ notebook := ""+ if nil != arg["notebook"] {+ notebook = arg["notebook"].(string)+ }+ typ := model.HistoryTypeDoc+ if nil != arg["type"] {+ typ = int(arg["type"].(float64))+ }+query := arg["query"].(string)page := 1if nil != arg["page"] {@@ -44,7 +53,7 @@ func searchHistory(c *gin.Context) {if nil != arg["op"] {op = arg["op"].(string)}- histories, pageCount, totalCount := model.FullTextSearchHistory(query, op, page)+ histories, pageCount, totalCount := model.FullTextSearchHistory(query, notebook, op, typ, page)ret.Data = map[string]interface{}{"histories": histories,"pageCount": pageCount,@@ -80,31 +89,6 @@ func getNotebookHistory(c *gin.Context) {}}-func getAssetsHistory(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- page := 1- if nil != arg["page"] {- page = int(arg["page"].(float64))- }- histories, err := model.GetAssetsHistory(page)- if nil != err {- ret.Code = -1- ret.Msg = err.Error()- return- }-- ret.Data = map[string]interface{}{- "histories": histories,- }-}-func clearWorkspaceHistory(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)@@ -122,33 +106,6 @@ func clearWorkspaceHistory(c *gin.Context) {util.PushMsg(model.Conf.Language(99), 1000*5)}-func getDocHistory(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- notebook := arg["notebook"].(string)- page := 1- if nil != arg["page"] {- page = int(arg["page"].(float64))- }- histories, err := model.GetDocHistory(notebook, page)- if nil != err {- ret.Code = -1- ret.Msg = err.Error()- return- }-- ret.Data = map[string]interface{}{- "box": notebook,- "histories": histories,- }-}-func getDocHistoryContent(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)diff --git a/kernel/api/router.go b/kernel/api/router.goindex 2c851eb9ed..a38033eed4 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -95,9 +95,7 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/history/getNotebookHistory", model.CheckAuth, getNotebookHistory)ginServer.Handle("POST", "/api/history/rollbackNotebookHistory", model.CheckAuth, rollbackNotebookHistory)- ginServer.Handle("POST", "/api/history/getAssetsHistory", model.CheckAuth, getAssetsHistory)ginServer.Handle("POST", "/api/history/rollbackAssetsHistory", model.CheckAuth, rollbackAssetsHistory)- ginServer.Handle("POST", "/api/history/getDocHistory", model.CheckAuth, getDocHistory)ginServer.Handle("POST", "/api/history/getDocHistoryContent", model.CheckAuth, getDocHistoryContent)ginServer.Handle("POST", "/api/history/rollbackDocHistory", model.CheckAuth, model.CheckReadonly, rollbackDocHistory)ginServer.Handle("POST", "/api/history/clearWorkspaceHistory", model.CheckAuth, model.CheckReadonly, clearWorkspaceHistory)diff --git a/kernel/model/history.go b/kernel/model/history.goindex 7088d4db53..23ec4b38d3 100644--- a/kernel/model/history.go+++ b/kernel/model/history.go@@ -262,21 +262,7 @@ type HistoryItem struct {Path string `json:"path"`}-func GetDocHistory(boxID string, page int) (ret []*History, err error) {- pageSize := 32- from := (page - 1) * pageSize- to := page * pageSize-- table := "histories_fts_case_insensitive"- projections := "type, op, title, content, path, created"- stmt := "SELECT " + projections + " FROM " + table + " WHERE path LIKE '%/" + boxID + "/%.sy'"- stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(from) + ", " + strconv.Itoa(to)- sqlHistories := sql.SelectHistoriesRawStmt(stmt)- ret = fromSQLHistories(sqlHistories)- return-}--func FullTextSearchHistory(query, op string, page int) (ret []*History, pageCount, totalCount int) {+func FullTextSearchHistory(query, box, op string, typ, page int) (ret []*History, pageCount, totalCount int) {query = gulu.Str.RemoveInvisible(query)query = stringQuery(query)@@ -289,6 +275,12 @@ func FullTextSearchHistory(query, op string, page int) (ret []*History, pageCounif "all" != op {stmt += " AND op = '" + op + "'"}++ if HistoryTypeDoc == typ {+ stmt += " AND path LIKE '%/" + box + "/%'"+ } else if HistoryTypeAsset == typ {+ stmt += " AND path LIKE '%/assets/%'"+ }countStmt := strings.ReplaceAll(stmt, "SELECT *", "SELECT COUNT(*) AS total")stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(from) + ", " + strconv.Itoa(to)sqlHistories := sql.SelectHistoriesRawStmt(stmt)@@ -300,7 +292,7 @@ func FullTextSearchHistory(query, op string, page int) (ret []*History, pageCounif 1 > len(result) {return}- totalCount = int(result[0]["matches"].(int64))+ totalCount = int(result[0]["total"].(int64))pageCount = int(math.Ceil(float64(totalCount) / float64(pageSize)))return}@@ -357,20 +349,6 @@ func GetNotebookHistory() (ret []*History, err error) {return}-func GetAssetsHistory(page int) (ret []*History, err error) {- pageSize := 32- from := (page - 1) * pageSize- to := page * pageSize-- table := "histories_fts_case_insensitive"- projections := "type, op, title, content, path, created"- stmt := "SELECT " + projections + " FROM " + table + " WHERE path LIKE '%/assets/%'"- stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(from) + ", " + strconv.Itoa(to)- sqlHistories := sql.SelectHistoriesRawStmt(stmt)- ret = fromSQLHistories(sqlHistories)- return-}-func (box *Box) generateDocHistory0() {files := box.recentModifiedDocs()if 1 > len(files) {@@ -528,6 +506,11 @@ func ReindexHistory() (err error) {var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat, HistoryOpSync}+const (+ HistoryTypeDoc = 0+ HistoryTypeAsset = 1+)+func indexHistoryDir(name string, luteEngine *lute.Lute) (err error) {op := name[strings.LastIndex(name, "-")+1:]if !gulu.Str.Contains(op, validOps) {@@ -566,7 +549,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) (err error) {p := strings.TrimPrefix(doc, util.HistoryDir)p = filepath.ToSlash(p[1:])histories = append(histories, &sql.History{- Type: 0,+ Type: HistoryTypeDoc,Op: op,Title: title,Content: content,@@ -579,7 +562,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) (err error) {p := strings.TrimPrefix(asset, util.HistoryDir)p = filepath.ToSlash(p[1:])histories = append(histories, &sql.History{- Type: 1,+ Type: HistoryTypeAsset,Op: op,Title: filepath.Base(asset),Path: p,