From 65f747fbf266d9345dd42f0676b58ebcfcefedbf Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 18 Dec 2023 10:04:42 +0800 Subject: [PATCH] :art: Enable or disable all CSS and JS code snippets https://github.com/siyuan-note/siyuan/issues/9860 --- kernel/api/router.go | 1 + kernel/api/setting.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/kernel/api/router.go b/kernel/api/router.go index 4d05190c8..49138e216 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -310,6 +310,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/setting/refreshVirtualBlockRef", model.CheckAuth, model.CheckReadonly, refreshVirtualBlockRef) 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/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 9229dc6a7..3e546a7c5 100644 --- a/kernel/api/setting.go +++ b/kernel/api/setting.go @@ -29,6 +29,35 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func setConfSnippet(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + param, err := gulu.JSON.MarshalJSON(arg) + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + snippet := &conf.Snpt{} + if err = gulu.JSON.UnmarshalJSON(param, snippet); nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + model.Conf.Snippet = snippet + model.Conf.Save() + + ret.Data = snippet +} + func addVirtualBlockRefExclude(c *gin.Context) { // Add internal kernel API `/api/setting/addVirtualBlockRefExclude` https://github.com/siyuan-note/siyuan/issues/9909