Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
d61d22d679
5 changed files with 86 additions and 5 deletions
|
@ -21,10 +21,52 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/riff"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func reviewRiffCard(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
deckName := arg["deck"].(string)
|
||||
blockID := arg["blockID"].(string)
|
||||
rating := int(arg["rating"].(float64))
|
||||
err := model.ReviewFlashcard(deckName, blockID, riff.Rating(rating))
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getRiffDueCards(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
deckName := arg["deck"].(string)
|
||||
|
||||
cards, err := model.GetDueFlashcards(deckName)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = cards
|
||||
}
|
||||
|
||||
func removeRiffCard(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
@ -302,6 +302,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/riff/createRiffDeck", model.CheckAuth, createRiffDeck)
|
||||
ginServer.Handle("POST", "/api/riff/addRiffCard", model.CheckAuth, addRiffCard)
|
||||
ginServer.Handle("POST", "/api/riff/removeRiffCard", model.CheckAuth, removeRiffCard)
|
||||
ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards)
|
||||
ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)
|
||||
|
||||
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
||||
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
||||
|
|
|
@ -45,7 +45,7 @@ require (
|
|||
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
|
||||
github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8
|
||||
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a
|
||||
github.com/siyuan-note/riff v0.0.0-20221221071610-c02c46f4ae00
|
||||
github.com/siyuan-note/riff v0.0.0-20221221075652-94b5ba658f10
|
||||
github.com/steambap/captcha v1.4.1
|
||||
github.com/studio-b12/gowebdav v0.0.0-20221109171924-60ec5ad56012
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5
|
||||
|
|
|
@ -385,10 +385,8 @@ github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8 h1:cv0U38yu
|
|||
github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8/go.mod h1:aLj3LQVz2iuA3AUfkqk1UvPhqafRpthAVtjV1+ZAq+U=
|
||||
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccYjsadwNBI11he+Wn25hI9lCma4uYoIYEM=
|
||||
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221064021-0e7597311cb0 h1:i2vxI2USCiNqyExpsy96TuvTO6Yhk7s+4hrPJ5MDOhI=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221064021-0e7597311cb0/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221071610-c02c46f4ae00 h1:oJHGup7FFSUNxQpnwqDjUnEbvAf18UbaJygGJpEXrUk=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221071610-c02c46f4ae00/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221075652-94b5ba658f10 h1:/7utWz6828wtcX2BjR6pu9pYEo6ThmKm1fXvAXLwPng=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221075652-94b5ba658f10/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=
|
||||
|
|
|
@ -32,6 +32,45 @@ import (
|
|||
var Decks = map[string]*riff.Deck{}
|
||||
var deckLock = sync.Mutex{}
|
||||
|
||||
func ReviewFlashcard(deckName string, blockID string, rating riff.Rating) (err error) {
|
||||
deckLock.Lock()
|
||||
deck := Decks[deckName]
|
||||
deckLock.Unlock()
|
||||
|
||||
deck.Review(blockID, rating)
|
||||
err = deck.Save()
|
||||
if nil != err {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckName, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type Flashcard struct {
|
||||
ID string
|
||||
BlockID string
|
||||
}
|
||||
|
||||
func GetDueFlashcards(deckName string) (ret []*Flashcard, err error) {
|
||||
deckLock.Lock()
|
||||
deck := Decks[deckName]
|
||||
deckLock.Unlock()
|
||||
|
||||
cards := deck.Dues()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
_, getErr := GetBlock(blockID)
|
||||
if nil != getErr {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, &Flashcard{
|
||||
ID: card.ID(),
|
||||
BlockID: blockID,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveFlashcard(blockID string, deckName string) (err error) {
|
||||
deckLock.Lock()
|
||||
deck := Decks[deckName]
|
||||
|
|
Loading…
Add table
Reference in a new issue