🎨 Export related flashcard data when exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/9372
This commit is contained in:
parent
a8806968d0
commit
8733433eb1
2 changed files with 44 additions and 14 deletions
|
@ -1385,22 +1385,21 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
|
||||
// 导出闪卡 Export related flashcard data when exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/9372
|
||||
exportStorageRiffDir := filepath.Join(exportFolder, "storage", "riff")
|
||||
deckID := ast.NewNodeID()
|
||||
deck, loadErr := riff.LoadDeck(exportStorageRiffDir, deckID, Conf.Flashcard.RequestRetention, Conf.Flashcard.MaximumInterval, Conf.Flashcard.Weights)
|
||||
for _, tree := range trees {
|
||||
cards := getTreeFlashcards(tree.ID)
|
||||
if nil != loadErr {
|
||||
logging.LogErrorf("load deck [%s] failed: %s", name, loadErr)
|
||||
continue
|
||||
}
|
||||
deck, loadErr := riff.LoadDeck(exportStorageRiffDir, builtinDeckID, Conf.Flashcard.RequestRetention, Conf.Flashcard.MaximumInterval, Conf.Flashcard.Weights)
|
||||
if nil != loadErr {
|
||||
logging.LogErrorf("load deck [%s] failed: %s", name, loadErr)
|
||||
} else {
|
||||
for _, tree := range trees {
|
||||
cards := getTreeFlashcards(tree.ID)
|
||||
|
||||
for _, card := range cards {
|
||||
deck.AddCard(card.ID(), card.BlockID())
|
||||
for _, card := range cards {
|
||||
deck.AddCard(card.ID(), card.BlockID())
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 < deck.CountCards() {
|
||||
if saveErr := deck.Save(); nil != saveErr {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", name, saveErr)
|
||||
if 0 < deck.CountCards() {
|
||||
if saveErr := deck.Save(); nil != saveErr {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", name, saveErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/siyuan-note/riff"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
|
@ -277,6 +278,36 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// 将关联的闪卡数据合并到默认卡包 data/storage/riff/20230218211946-2kw8jgx 中
|
||||
storageRiffDir := filepath.Join(storage, "riff")
|
||||
if gulu.File.IsExist(storageRiffDir) {
|
||||
deckToImport, loadErr := riff.LoadDeck(storageRiffDir, builtinDeckID, Conf.Flashcard.RequestRetention, Conf.Flashcard.MaximumInterval, Conf.Flashcard.Weights)
|
||||
if nil != loadErr {
|
||||
logging.LogErrorf("load deck [%s] failed: %s", name, loadErr)
|
||||
} else {
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
var createErr error
|
||||
deck, createErr = createDeck0("Built-in Deck", builtinDeckID)
|
||||
if nil == createErr {
|
||||
Decks[deck.ID] = deck
|
||||
}
|
||||
}
|
||||
|
||||
bIDs := deckToImport.GetBlockIDs()
|
||||
cards := deckToImport.GetCardsByBlockIDs(bIDs)
|
||||
for _, card := range cards {
|
||||
deck.AddCard(card.ID(), blockIDs[card.BlockID()])
|
||||
}
|
||||
|
||||
if 0 < len(cards) {
|
||||
if saveErr := deck.Save(); nil != saveErr {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", name, saveErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// storage 文件夹已在上方处理,所以这里删除源 storage 文件夹,避免后面被拷贝到导入目录下 targetDir
|
||||
if removeErr := os.RemoveAll(storage); nil != removeErr {
|
||||
logging.LogErrorf("remove temp storage av dir failed: %s", removeErr)
|
||||
|
|
Loading…
Add table
Reference in a new issue