From 7d450f88eb58d1616339ce9f270a7152c16d0f86 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 21:46:35 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=8D=A1=E5=8C=85=E5=86=85=E7=9A=84=E9=97=AA=E5=8D=A1=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/6943?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 5 +++-- kernel/api/router.go | 2 +- kernel/model/flashcard.go | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 9d2ea5fa2..fb8bc54f0 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -27,7 +27,7 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func searchRiffCards(c *gin.Context) { +func getRiffCards(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) @@ -37,7 +37,8 @@ func searchRiffCards(c *gin.Context) { } deckID := arg["deckID"].(string) - blockIDs := model.SearchFlashcard(deckID) + page := int(arg["page"].(float64)) + blockIDs := model.GetFlashcards(deckID, page) ret.Data = map[string]interface{}{ "blockIDs": blockIDs, } diff --git a/kernel/api/router.go b/kernel/api/router.go index f65db1623..cb3bf3d5d 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -308,7 +308,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards) ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards) ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard) - ginServer.Handle("POST", "/api/riff/searchRiffCards", model.CheckAuth, searchRiffCards) + ginServer.Handle("POST", "/api/riff/getRiffCards", model.CheckAuth, getRiffCards) ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg) ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 09bcdfe27..4d45ad4d8 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -20,6 +20,7 @@ import ( "errors" "os" "path/filepath" + "sort" "strings" "sync" "time" @@ -38,7 +39,27 @@ import ( var Decks = map[string]*riff.Deck{} var deckLock = sync.Mutex{} -func SearchFlashcard(deckID string) (blockIDs []string) { +func GetFlashcards(deckID string, page int) (blockIDs []string) { + deck := Decks[deckID] + if nil == deck { + return + } + + var allBlockIDs []string + for bID, _ := range deck.BlockCard { + allBlockIDs = append(allBlockIDs, bID) + } + sort.Strings(allBlockIDs) + + start := (page - 1) * 20 + end := page * 20 + if start > len(allBlockIDs) { + return + } + if end > len(allBlockIDs) { + end = len(allBlockIDs) + } + blockIDs = allBlockIDs[start:end] return }