mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 05:42:12 +08:00
🎨 Add kernel API /api/riff/getRiffCardsByBlockIDs
Fix https://github.com/siyuan-note/siyuan/issues/10535
This commit is contained in:
parent
e083dacca8
commit
fd709b99b7
@ -40,17 +40,10 @@ func getRiffCardsByBlockIDs(c *gin.Context) {
|
|||||||
for _, blockID := range blockIDsArg {
|
for _, blockID := range blockIDsArg {
|
||||||
blockIDs = append(blockIDs, blockID.(string))
|
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)
|
blocks := model.GetFlashcardsByBlockIDs(blockIDs)
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"blocks": blocks,
|
"blocks": blocks,
|
||||||
"total": total,
|
|
||||||
"pageCount": pageCount,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,19 +38,37 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFlashcardsByBlockIDs(blockIDs []string, page, pageSize int) (blocks []*Block, total, pageCount int) {
|
func GetFlashcardsByBlockIDs(blockIDs []string) (ret []*Block) {
|
||||||
deckLock.Lock()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
|
||||||
waitForSyncingStorages()
|
waitForSyncingStorages()
|
||||||
|
|
||||||
|
ret = []*Block{}
|
||||||
deck := Decks[builtinDeckID]
|
deck := Decks[builtinDeckID]
|
||||||
if nil == deck {
|
if nil == deck {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cards := deck.GetCardsByBlockIDs(blockIDs)
|
cards := deck.GetCardsByBlockIDs(blockIDs)
|
||||||
blocks, total, pageCount = getCardsBlocks(cards, page, pageSize)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user