mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 19:40:48 +08:00
🐛 默认闪卡包移除后卡住 Fix https://github.com/siyuan-note/siyuan/issues/6946
This commit is contained in:
parent
7797750ae8
commit
c4ba046898
@ -27,7 +27,7 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func renderRiffCard(c *gin.Context) {
|
func searchRiffCards(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
@ -36,16 +36,10 @@ func renderRiffCard(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockID := arg["blockID"].(string)
|
deckID := arg["deckID"].(string)
|
||||||
content, err := model.RenderFlashcard(blockID)
|
blockIDs := model.SearchFlashcard(deckID)
|
||||||
if nil != err {
|
|
||||||
ret.Code = -1
|
|
||||||
ret.Msg = err.Error()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
"content": content,
|
"blockIDs": blockIDs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,8 +307,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards)
|
ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards)
|
||||||
ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards)
|
ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards)
|
||||||
ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards)
|
ginServer.Handle("POST", "/api/riff/getRiffDueCards", model.CheckAuth, getRiffDueCards)
|
||||||
ginServer.Handle("POST", "/api/riff/renderRiffCard", model.CheckAuth, renderRiffCard)
|
|
||||||
ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)
|
ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)
|
||||||
|
ginServer.Handle("POST", "/api/riff/searchRiffCards", model.CheckAuth, searchRiffCards)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
||||||
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute"
|
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
@ -39,23 +38,7 @@ import (
|
|||||||
var Decks = map[string]*riff.Deck{}
|
var Decks = map[string]*riff.Deck{}
|
||||||
var deckLock = sync.Mutex{}
|
var deckLock = sync.Mutex{}
|
||||||
|
|
||||||
func RenderFlashcard(blockID string) (content string, err error) {
|
func SearchFlashcard(deckID string) (blockIDs []string) {
|
||||||
tree, err := loadTreeByBlockID(blockID)
|
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
node := treenode.GetNodeInTree(tree, blockID)
|
|
||||||
if nil == node {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
luteEngine := NewLute()
|
|
||||||
if ast.NodeDocument == node.Type {
|
|
||||||
content = luteEngine.Tree2BlockDOM(tree, luteEngine.RenderOptions)
|
|
||||||
} else {
|
|
||||||
content = lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +348,7 @@ func InitFlashcards() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 1 > len(Decks) {
|
if 1 > len(Decks) {
|
||||||
deck, createErr := CreateDeck("Default Deck")
|
deck, createErr := createDeck("Default Deck")
|
||||||
if nil == createErr {
|
if nil == createErr {
|
||||||
Decks[deck.ID] = deck
|
Decks[deck.ID] = deck
|
||||||
}
|
}
|
||||||
@ -402,12 +385,17 @@ func RemoveDeck(deckID string) (err error) {
|
|||||||
|
|
||||||
riffSavePath := getRiffDir()
|
riffSavePath := getRiffDir()
|
||||||
deckPath := filepath.Join(riffSavePath, deckID+".deck")
|
deckPath := filepath.Join(riffSavePath, deckID+".deck")
|
||||||
if err = os.Remove(deckPath); nil != err {
|
if gulu.File.IsExist(deckPath) {
|
||||||
return
|
if err = os.Remove(deckPath); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cardsPath := filepath.Join(riffSavePath, deckID+".cards")
|
cardsPath := filepath.Join(riffSavePath, deckID+".cards")
|
||||||
if err = os.Remove(cardsPath); nil != err {
|
if gulu.File.IsExist(cardsPath) {
|
||||||
return
|
if err = os.Remove(cardsPath); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InitFlashcards()
|
InitFlashcards()
|
||||||
@ -417,7 +405,10 @@ func RemoveDeck(deckID string) (err error) {
|
|||||||
func CreateDeck(name string) (deck *riff.Deck, err error) {
|
func CreateDeck(name string) (deck *riff.Deck, err error) {
|
||||||
deckLock.Lock()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
return createDeck(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createDeck(name string) (deck *riff.Deck, err error) {
|
||||||
if syncingStorages {
|
if syncingStorages {
|
||||||
err = errors.New(Conf.Language(81))
|
err = errors.New(Conf.Language(81))
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user