mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
🎨 Improve create workspace interaction https://github.com/siyuan-note/siyuan/issues/8700
This commit is contained in:
parent
8ad1732896
commit
df991abe98
2 changed files with 44 additions and 0 deletions
|
|
@ -47,6 +47,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/system/setWorkspaceDir", model.CheckAuth, model.CheckReadonly, setWorkspaceDir)
|
ginServer.Handle("POST", "/api/system/setWorkspaceDir", model.CheckAuth, model.CheckReadonly, setWorkspaceDir)
|
||||||
ginServer.Handle("POST", "/api/system/getWorkspaces", model.CheckAuth, getWorkspaces)
|
ginServer.Handle("POST", "/api/system/getWorkspaces", model.CheckAuth, getWorkspaces)
|
||||||
ginServer.Handle("POST", "/api/system/getMobileWorkspaces", model.CheckAuth, getMobileWorkspaces)
|
ginServer.Handle("POST", "/api/system/getMobileWorkspaces", model.CheckAuth, getMobileWorkspaces)
|
||||||
|
ginServer.Handle("POST", "/api/system/checkWorkspaceDir", model.CheckAuth, model.CheckReadonly, checkWorkspaceDir)
|
||||||
ginServer.Handle("POST", "/api/system/createWorkspaceDir", model.CheckAuth, model.CheckReadonly, createWorkspaceDir)
|
ginServer.Handle("POST", "/api/system/createWorkspaceDir", model.CheckAuth, model.CheckReadonly, createWorkspaceDir)
|
||||||
ginServer.Handle("POST", "/api/system/removeWorkspaceDir", model.CheckAuth, model.CheckReadonly, removeWorkspaceDir)
|
ginServer.Handle("POST", "/api/system/removeWorkspaceDir", model.CheckAuth, model.CheckReadonly, removeWorkspaceDir)
|
||||||
ginServer.Handle("POST", "/api/system/setAppearanceMode", model.CheckAuth, setAppearanceMode)
|
ginServer.Handle("POST", "/api/system/setAppearanceMode", model.CheckAuth, setAppearanceMode)
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,49 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkWorkspaceDir(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
path := arg["path"].(string)
|
||||||
|
if isInvalidWorkspacePath(path) {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "This workspace name is not allowed, please use another name"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !gulu.File.IsExist(path) {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "This workspace does not exist"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(path)
|
||||||
|
if nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = fmt.Sprintf("read workspace dir [%s] failed: %s", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var existsConf, existsData bool
|
||||||
|
for _, entry := range entries {
|
||||||
|
existsConf = "conf" == entry.Name() && entry.IsDir()
|
||||||
|
existsData = "data" == entry.Name() && entry.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
if existsConf {
|
||||||
|
existsConf = gulu.File.IsExist(filepath.Join(path, "conf", "conf.json"))
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"isWorkspace": existsConf && existsData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createWorkspaceDir(c *gin.Context) {
|
func createWorkspaceDir(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue