This commit is contained in:
Liang Ding 2022-12-29 21:46:35 +08:00
parent c4ba046898
commit 7d450f88eb
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 26 additions and 4 deletions

View file

@ -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
}