🎨 Improve create workspace interaction https://github.com/siyuan-note/siyuan/issues/8700

This commit is contained in:
Daniel 2023-07-07 18:55:52 +08:00
parent 8ad1732896
commit df991abe98
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 44 additions and 0 deletions

View file

@ -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/getWorkspaces", model.CheckAuth, getWorkspaces)
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/removeWorkspaceDir", model.CheckAuth, model.CheckReadonly, removeWorkspaceDir)
ginServer.Handle("POST", "/api/system/setAppearanceMode", model.CheckAuth, setAppearanceMode)

View file

@ -34,6 +34,49 @@ import (
"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) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)