Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
ab2664fb9c
4 changed files with 65 additions and 4 deletions
|
@ -27,6 +27,26 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getRiffCardsByBlockIDs(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
blockIDsArg := arg["blockIDs"].([]interface{})
|
||||
var blockIDs []string
|
||||
for _, blockID := range blockIDsArg {
|
||||
blockIDs = append(blockIDs, blockID.(string))
|
||||
}
|
||||
|
||||
blocks := model.GetFlashcardsByBlockIDs(blockIDs)
|
||||
ret.Data = map[string]interface{}{
|
||||
"blocks": blocks,
|
||||
}
|
||||
}
|
||||
|
||||
func batchSetRiffCardsDueTime(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
@ -387,6 +387,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/riff/getNotebookRiffCards", model.CheckAuth, getNotebookRiffCards)
|
||||
ginServer.Handle("POST", "/api/riff/resetRiffCards", model.CheckAuth, model.CheckReadonly, resetRiffCards)
|
||||
ginServer.Handle("POST", "/api/riff/batchSetRiffCardsDueTime", model.CheckAuth, model.CheckReadonly, batchSetRiffCardsDueTime)
|
||||
ginServer.Handle("POST", "/api/riff/getRiffCardsByBlockIDs", model.CheckAuth, model.CheckReadonly, getRiffCardsByBlockIDs)
|
||||
|
||||
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
||||
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
||||
|
|
|
@ -67,8 +67,11 @@ type Block struct {
|
|||
}
|
||||
|
||||
type RiffCard struct {
|
||||
Due time.Time `json:"due"`
|
||||
Reps uint64 `json:"reps"`
|
||||
Due time.Time `json:"due"`
|
||||
Reps uint64 `json:"reps"`
|
||||
Lapses uint64 `json:"lapses"`
|
||||
State fsrs.State `json:"state"`
|
||||
LastReview time.Time `json:"lastReview"`
|
||||
}
|
||||
|
||||
func getRiffCard(card *fsrs.Card) *RiffCard {
|
||||
|
@ -78,8 +81,11 @@ func getRiffCard(card *fsrs.Card) *RiffCard {
|
|||
}
|
||||
|
||||
return &RiffCard{
|
||||
Due: due,
|
||||
Reps: card.Reps,
|
||||
Due: due,
|
||||
Reps: card.Reps,
|
||||
Lapses: card.Lapses,
|
||||
State: card.State,
|
||||
LastReview: card.LastReview,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,40 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func GetFlashcardsByBlockIDs(blockIDs []string) (ret []*Block) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
waitForSyncingStorages()
|
||||
|
||||
ret = []*Block{}
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
|
||||
cards := deck.GetCardsByBlockIDs(blockIDs)
|
||||
blocks, _, _ := getCardsBlocks(cards, 1, math.MaxInt)
|
||||
|
||||
for _, blockID := range blockIDs {
|
||||
found := false
|
||||
for _, block := range blocks {
|
||||
if blockID == block.ID {
|
||||
found = true
|
||||
ret = append(ret, block)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
ret = append(ret, &Block{
|
||||
ID: blockID,
|
||||
Content: Conf.Language(180),
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type SetFlashcardDueTime struct {
|
||||
ID string `json:"id"` // 卡片 ID
|
||||
Due string `json:"due"` // 下次复习时间,格式为 YYYYMMDDHHmmss
|
||||
|
|
Loading…
Add table
Reference in a new issue