Skip to content

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

:art: 支持工作空间快捷切换

Liang Dingdc4b5accfba3
diff --git a/kernel/api/router.go b/kernel/api/router.go
index b854a1ddc5..1afca1e148 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -45,7 +45,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/setDownloadInstallPkg", model.CheckAuth, setDownloadInstallPkg)
ginServer.Handle("POST", "/api/system/setNetworkProxy", model.CheckAuth, setNetworkProxy)
ginServer.Handle("POST", "/api/system/setWorkspaceDir", model.CheckAuth, setWorkspaceDir)
- ginServer.Handle("POST", "/api/system/listWorkspaceDirs", model.CheckAuth, listWorkspaceDirs)
+ ginServer.Handle("POST", "/api/system/getWorkspaces", model.CheckAuth, getWorkspaces)
ginServer.Handle("POST", "/api/system/createWorkspaceDir", model.CheckAuth, createWorkspaceDir)
ginServer.Handle("POST", "/api/system/removeWorkspaceDir", model.CheckAuth, removeWorkspaceDir)
ginServer.Handle("POST", "/api/system/setAppearanceMode", model.CheckAuth, setAppearanceMode)
@@ -106,7 +106,6 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/filetree/heading2Doc", model.CheckAuth, model.CheckReadonly, heading2Doc)
ginServer.Handle("POST", "/api/filetree/li2Doc", model.CheckAuth, model.CheckReadonly, li2Doc)
ginServer.Handle("POST", "/api/filetree/refreshFiletree", model.CheckAuth, model.CheckReadonly, refreshFiletree)
- ginServer.Handle("POST", "/api/filetree/reindexTree", model.CheckAuth, model.CheckReadonly, reindexTree)
ginServer.Handle("POST", "/api/format/autoSpace", model.CheckAuth, model.CheckReadonly, autoSpace)
ginServer.Handle("POST", "/api/format/netImg2LocalAssets", model.CheckAuth, model.CheckReadonly, netImg2LocalAssets)
diff --git a/kernel/api/workspace.go b/kernel/api/workspace.go
index b5a4ad1e4d..fb38899862 100644
--- a/kernel/api/workspace.go
+++ b/kernel/api/workspace.go
@@ -28,6 +28,7 @@ import (
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
+ "github.com/gofrs/flock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -117,7 +118,12 @@ func removeWorkspaceDir(c *gin.Context) {
}
}
-func listWorkspaceDirs(c *gin.Context) {
+type Workspace struct {
+ Path string `json:"path"`
+ Closed bool `json:"closed"`
+}
+
+func getWorkspaces(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@@ -127,7 +133,17 @@ func listWorkspaceDirs(c *gin.Context) {
ret.Msg = err.Error()
return
}
- ret.Data = workspacePaths
+
+ var workspaces []*Workspace
+ for _, p := range workspacePaths {
+ closed := true
+ if flock.New(filepath.Join(p, ".lock")).Locked() {
+ closed = false
+ }
+
+ workspaces = append(workspaces, &Workspace{Path: p, Closed: closed})
+ }
+ ret.Data = workspaces
}
func setWorkspaceDir(c *gin.Context) {