浏览代码

:art: 闪卡配置

Liang Ding 2 年之前
父节点
当前提交
60f390d9e0
共有 2 个文件被更改,包括 38 次插入0 次删除
  1. 1 0
      kernel/api/router.go
  2. 37 0
      kernel/api/setting.go

+ 1 - 0
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)

+ 37 - 0
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)