This commit is contained in:
Liang Ding 2022-12-29 20:57:16 +08:00
parent 7797750ae8
commit c4ba046898
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
3 changed files with 19 additions and 34 deletions

View File

@ -27,7 +27,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func renderRiffCard(c *gin.Context) {
func searchRiffCards(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@ -36,16 +36,10 @@ func renderRiffCard(c *gin.Context) {
return
}
blockID := arg["blockID"].(string)
content, err := model.RenderFlashcard(blockID)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
}
deckID := arg["deckID"].(string)
blockIDs := model.SearchFlashcard(deckID)
ret.Data = map[string]interface{}{
"content": content,
"blockIDs": blockIDs,
}
}

View File

@ -307,8 +307,8 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards)
ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards)
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/searchRiffCards", model.CheckAuth, searchRiffCards)
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)

View File

@ -25,7 +25,6 @@ import (
"time"
"github.com/88250/gulu"
"github.com/88250/lute"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/dustin/go-humanize"
@ -39,23 +38,7 @@ import (
var Decks = map[string]*riff.Deck{}
var deckLock = sync.Mutex{}
func RenderFlashcard(blockID string) (content string, err error) {
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)
}
func SearchFlashcard(deckID string) (blockIDs []string) {
return
}
@ -365,7 +348,7 @@ func InitFlashcards() {
}
if 1 > len(Decks) {
deck, createErr := CreateDeck("Default Deck")
deck, createErr := createDeck("Default Deck")
if nil == createErr {
Decks[deck.ID] = deck
}
@ -402,13 +385,18 @@ func RemoveDeck(deckID string) (err error) {
riffSavePath := getRiffDir()
deckPath := filepath.Join(riffSavePath, deckID+".deck")
if gulu.File.IsExist(deckPath) {
if err = os.Remove(deckPath); nil != err {
return
}
}
cardsPath := filepath.Join(riffSavePath, deckID+".cards")
if gulu.File.IsExist(cardsPath) {
if err = os.Remove(cardsPath); nil != err {
return
}
}
InitFlashcards()
return
@ -417,7 +405,10 @@ func RemoveDeck(deckID string) (err error) {
func CreateDeck(name string) (deck *riff.Deck, err error) {
deckLock.Lock()
defer deckLock.Unlock()
return createDeck(name)
}
func createDeck(name string) (deck *riff.Deck, err error) {
if syncingStorages {
err = errors.New(Conf.Language(81))
return