🎨 支持工作空间快捷切换

This commit is contained in:
Liang Ding 2023-01-08 22:44:36 +08:00
parent 1adcf9ca6c
commit dc4b5accfb
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 19 additions and 4 deletions

View file

@ -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)

View file

@ -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) {