From b85f1831b47c47de7c38a9bbaa454bb3d0cde2ae Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 21 Mar 2023 18:59:54 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=86=85=E9=85=8D=E7=BD=AE=E4=BA=BA=E5=B7=A5=E6=99=BA=E8=83=BD?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/7714?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 dffd6c0ee..13b809899 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -263,6 +263,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/setting/setCustomCSS", model.CheckAuth, model.CheckReadonly, setCustomCSS) ginServer.Handle("POST", "/api/setting/setEmoji", model.CheckAuth, model.CheckReadonly, setEmoji) ginServer.Handle("POST", "/api/setting/setFlashcard", model.CheckAuth, model.CheckReadonly, setFlashcard) + ginServer.Handle("POST", "/api/setting/setAI", model.CheckAuth, model.CheckReadonly, setAI) 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 ce33153e1..fc0070e6a 100644 --- a/kernel/api/setting.go +++ b/kernel/api/setting.go @@ -29,6 +29,35 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func setAI(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 + } + + ai := &conf.AI{} + if err = gulu.JSON.UnmarshalJSON(param, ai); nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + model.Conf.AI = ai + model.Conf.Save() + + ret.Data = ai +} + func setFlashcard(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret)