Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Add kernel API `/api/riff/getRiffCardsByBlockIDs` Fix https://github.com/siyuan-note/siyuan/issues/10535

Daniele083dacca866
diff --git a/kernel/api/riff.go b/kernel/api/riff.go
index 6178c8e181..7bd00621e9 100644
--- a/kernel/api/riff.go
+++ b/kernel/api/riff.go
@@ -27,6 +27,33 @@ 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))
+ }
+ page := int(arg["page"].(float64))
+ pageSize := 20
+ if nil != arg["pageSize"] {
+ pageSize = int(arg["pageSize"].(float64))
+ }
+
+ blocks, total, pageCount := model.GetFlashcardsByBlockIDs(blockIDs, page, pageSize)
+ ret.Data = map[string]interface{}{
+ "blocks": blocks,
+ "total": total,
+ "pageCount": pageCount,
+ }
+}
+
func batchSetRiffCardsDueTime(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
diff --git a/kernel/api/router.go b/kernel/api/router.go
index 354c47e262..318844e40f 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -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)
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 2779ad6089..2ca3eb5bbd 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -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,
}
}
diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go
index 38abbf24e5..182b392c6b 100644
--- a/kernel/model/flashcard.go
+++ b/kernel/model/flashcard.go
@@ -38,6 +38,22 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
+func GetFlashcardsByBlockIDs(blockIDs []string, page, pageSize int) (blocks []*Block, total, pageCount int) {
+ deckLock.Lock()
+ defer deckLock.Unlock()
+
+ waitForSyncingStorages()
+
+ deck := Decks[builtinDeckID]
+ if nil == deck {
+ return
+ }
+
+ cards := deck.GetCardsByBlockIDs(blockIDs)
+ blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)
+ return
+}
+
type SetFlashcardDueTime struct {
ID string `json:"id"` // 卡片 ID
Due string `json:"due"` // 下次复习时间,格式为 YYYYMMDDHHmmss