diff --git a/kernel/api/router.go b/kernel/api/router.go index 0be3f8526..271f30306 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -317,6 +317,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/setting/addVirtualBlockRefInclude", model.CheckAuth, model.CheckReadonly, addVirtualBlockRefInclude) ginServer.Handle("POST", "/api/setting/addVirtualBlockRefExclude", model.CheckAuth, model.CheckReadonly, addVirtualBlockRefExclude) ginServer.Handle("POST", "/api/setting/setSnippet", model.CheckAuth, model.CheckReadonly, setConfSnippet) + ginServer.Handle("POST", "/api/setting/setEditorReadOnly", model.CheckAuth, model.CheckReadonly, setEditorReadOnly) ginServer.Handle("POST", "/api/graph/resetGraph", model.CheckAuth, model.CheckReadonly, resetGraph) ginServer.Handle("POST", "/api/graph/resetLocalGraph", model.CheckAuth, model.CheckReadonly, resetLocalGraph) diff --git a/kernel/api/setting.go b/kernel/api/setting.go index e9c9c9d33..126966952 100644 --- a/kernel/api/setting.go +++ b/kernel/api/setting.go @@ -29,6 +29,27 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func setEditorReadOnly(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + readOnly := arg["readonly"].(bool) + + oldReadOnly := model.Conf.Editor.ReadOnly + model.Conf.Editor.ReadOnly = readOnly + model.Conf.Save() + + if oldReadOnly != model.Conf.Editor.ReadOnly { + util.BroadcastByType("protyle", "readonly", 0, "", model.Conf.Editor.ReadOnly) + util.BroadcastByType("main", "readonly", 0, "", model.Conf.Editor.ReadOnly) + } +} + func setConfSnippet(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret)