|
@@ -22,7 +22,6 @@ import (
|
|
|
"strings"
|
|
|
"sync"
|
|
|
|
|
|
- "github.com/88250/gulu"
|
|
|
"github.com/88250/lute/ast"
|
|
|
"github.com/siyuan-note/logging"
|
|
|
"github.com/siyuan-note/riff"
|
|
@@ -106,7 +105,8 @@ func AddFlashcards(deckID string, blockIDs []string) (err error) {
|
|
|
|
|
|
func InitFlashcards() {
|
|
|
riffSavePath := getRiffDir()
|
|
|
- if !gulu.File.IsDir(riffSavePath) {
|
|
|
+ if err := os.MkdirAll(riffSavePath, 0755); nil != err {
|
|
|
+ logging.LogErrorf("create riff dir [%s] failed: %s", riffSavePath, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -125,11 +125,30 @@ func InitFlashcards() {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- deckLock.Lock()
|
|
|
Decks[deckID] = deck
|
|
|
- deckLock.Unlock()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if 1 > len(Decks) {
|
|
|
+ deck, createErr := CreateDeck("Default Deck")
|
|
|
+ if nil == createErr {
|
|
|
+ Decks[deck.ID] = deck
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func RenameDeck(deckID string, name string) (err error) {
|
|
|
+ deckLock.Lock()
|
|
|
+ deck := Decks[deckID]
|
|
|
+ deckLock.Unlock()
|
|
|
+
|
|
|
+ deck.Name = name
|
|
|
+ err = deck.Save()
|
|
|
+ if nil != err {
|
|
|
+ logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func CreateDeck(name string) (deck *riff.Deck, err error) {
|