Browse Source

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 2 years ago
parent
commit
5b85d0e91b
4 changed files with 37 additions and 2 deletions
  1. 29 0
      kernel/api/history.go
  2. 2 0
      kernel/api/router.go
  3. 3 2
      kernel/model/history.go
  4. 3 0
      kernel/util/path.go

+ 29 - 0
kernel/api/history.go

@@ -26,6 +26,35 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 )
 
 
+func searchHistory(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	arg, ok := util.JsonArg(c, ret)
+	if !ok {
+		return
+	}
+
+	query := arg["query"].(string)
+	page := int(arg["page"].(float64))
+	histories := model.FullTextSearchHistory(query, page)
+	ret.Data = map[string]interface{}{
+		"histories": histories,
+	}
+}
+
+func reindexHistory(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	err := model.ReindexHistory()
+	if nil != err {
+		ret.Code = -1
+		ret.Msg = err.Error()
+		return
+	}
+}
+
 func getNotebookHistory(c *gin.Context) {
 func getNotebookHistory(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)

+ 2 - 0
kernel/api/router.go

@@ -101,6 +101,8 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/history/getDocHistoryContent", model.CheckAuth, getDocHistoryContent)
 	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/rollbackDocHistory", model.CheckAuth, model.CheckReadonly, rollbackDocHistory)
 	ginServer.Handle("POST", "/api/history/clearWorkspaceHistory", model.CheckAuth, model.CheckReadonly, clearWorkspaceHistory)
 	ginServer.Handle("POST", "/api/history/clearWorkspaceHistory", model.CheckAuth, model.CheckReadonly, clearWorkspaceHistory)
+	ginServer.Handle("POST", "/api/history/reindexHistory", model.CheckAuth, model.CheckReadonly, reindexHistory)
+	ginServer.Handle("POST", "/api/history/searchHistory", model.CheckAuth, model.CheckReadonly, searchHistory)
 
 
 	ginServer.Handle("POST", "/api/outline/getDocOutline", model.CheckAuth, getDocOutline)
 	ginServer.Handle("POST", "/api/outline/getDocOutline", model.CheckAuth, getDocOutline)
 	ginServer.Handle("POST", "/api/bookmark/getBookmark", model.CheckAuth, getBookmark)
 	ginServer.Handle("POST", "/api/bookmark/getBookmark", model.CheckAuth, getBookmark)

+ 3 - 2
kernel/model/history.go

@@ -611,7 +611,7 @@ func GetHistoryDir(suffix string) (ret string, err error) {
 	return
 	return
 }
 }
 
 
-func indexHistory() {
+func ReindexHistory() (err error) {
 	historyDirs, err := os.ReadDir(util.HistoryDir)
 	historyDirs, err := os.ReadDir(util.HistoryDir)
 	if nil != err {
 	if nil != err {
 		logging.LogErrorf("read history dir [%s] failed: %s", util.HistoryDir, err)
 		logging.LogErrorf("read history dir [%s] failed: %s", util.HistoryDir, err)
@@ -630,6 +630,7 @@ func indexHistory() {
 			return
 			return
 		}
 		}
 	}
 	}
+	return
 }
 }
 
 
 var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat}
 var validOps = []string{HistoryOpClean, HistoryOpUpdate, HistoryOpDelete, HistoryOpFormat}
@@ -713,7 +714,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) (err error) {
 	return
 	return
 }
 }
 
 
-func fullTextSearchHistory(query string, page int) (ret []*History, matchedBlockCount, matchedRootCount int) {
+func FullTextSearchHistory(query string, page int) (ret []*History) {
 	query = gulu.Str.RemoveInvisible(query)
 	query = gulu.Str.RemoveInvisible(query)
 	query = stringQuery(query)
 	query = stringQuery(query)
 
 

+ 3 - 0
kernel/util/path.go

@@ -112,6 +112,9 @@ func GetLocalIPs() (ret []string) {
 }
 }
 
 
 func isRunningInDockerContainer() bool {
 func isRunningInDockerContainer() bool {
+	if _, runInContainer := os.LookupEnv("RUN_IN_CONTAINER"); runInContainer {
+		return true
+	}
 	if _, err := os.Stat("/.dockerenv"); err == nil {
 	if _, err := os.Stat("/.dockerenv"); err == nil {
 		return true
 		return true
 	}
 	}