From 60f390d9e08c61cf4f5587c44f5a07d3a76c61c8 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 19 Mar 2023 17:06:09 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E9=97=AA=E5=8D=A1=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/router.go | 1 + kernel/api/setting.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/kernel/api/router.go b/kernel/api/router.go index b0f20efb3..b1bbb7feb 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/getCustomCSS", model.CheckAuth, getCustomCSS) 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/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 8f67456f5..ce33153e1 100644 --- a/kernel/api/setting.go +++ b/kernel/api/setting.go @@ -29,6 +29,43 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func setFlashcard(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 + } + + flashcard := &conf.Flashcard{} + if err = gulu.JSON.UnmarshalJSON(param, flashcard); nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + if 1 > flashcard.DailyNewCardLimit { + flashcard.DailyNewCardLimit = 1 + } + + if 1 > flashcard.DailyReviewCardLimit { + flashcard.DailyReviewCardLimit = 1 + } + + model.Conf.Flashcard = flashcard + model.Conf.Save() + + ret.Data = flashcard +} + func setAccount(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret)