mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 19:40:48 +08:00
This commit is contained in:
parent
b3b67832b0
commit
2abc5561b5
@ -67,7 +67,7 @@ func getRiffDueCards(c *gin.Context) {
|
||||
ret.Data = cards
|
||||
}
|
||||
|
||||
func removeRiffCard(c *gin.Context) {
|
||||
func removeRiffCards(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
@ -77,8 +77,12 @@ func removeRiffCard(c *gin.Context) {
|
||||
}
|
||||
|
||||
deckID := arg["deckID"].(string)
|
||||
blockID := arg["blockID"].(string)
|
||||
err := model.RemoveFlashcard(blockID, deckID)
|
||||
blockIDsArg := arg["blockIDs"].([]interface{})
|
||||
var blockIDs []string
|
||||
for _, blockID := range blockIDsArg {
|
||||
blockIDs = append(blockIDs, blockID.(string))
|
||||
}
|
||||
err := model.RemoveFlashcards(deckID, blockIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@ -86,7 +90,7 @@ func removeRiffCard(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func addRiffCard(c *gin.Context) {
|
||||
func addRiffCards(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
@ -96,8 +100,12 @@ func addRiffCard(c *gin.Context) {
|
||||
}
|
||||
|
||||
deckID := arg["deckID"].(string)
|
||||
blockID := arg["blockID"].(string)
|
||||
err := model.AddFlashcard(blockID, deckID)
|
||||
blockIDsArg := arg["blockIDs"].([]interface{})
|
||||
var blockIDs []string
|
||||
for _, blockID := range blockIDsArg {
|
||||
blockIDs = append(blockIDs, blockID.(string))
|
||||
}
|
||||
err := model.AddFlashcards(deckID, blockIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@ -115,12 +123,13 @@ func createRiffDeck(c *gin.Context) {
|
||||
}
|
||||
|
||||
name := arg["name"].(string)
|
||||
err := model.CreateDeck(name)
|
||||
deck, err := model.CreateDeck(name)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
ret.Data = deck
|
||||
}
|
||||
|
||||
func getRiffDecks(c *gin.Context) {
|
||||
|
@ -301,8 +301,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
|
||||
ginServer.Handle("POST", "/api/riff/createRiffDeck", model.CheckAuth, createRiffDeck)
|
||||
ginServer.Handle("POST", "/api/riff/getRiffDecks", model.CheckAuth, getRiffDecks)
|
||||
ginServer.Handle("POST", "/api/riff/addRiffCard", model.CheckAuth, addRiffCard)
|
||||
ginServer.Handle("POST", "/api/riff/removeRiffCard", model.CheckAuth, removeRiffCard)
|
||||
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/reviewRiffCard", model.CheckAuth, reviewRiffCard)
|
||||
|
||||
|
@ -45,7 +45,7 @@ require (
|
||||
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
|
||||
github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8
|
||||
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a
|
||||
github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c
|
||||
github.com/siyuan-note/riff v0.0.0-20221221142532-2c074735104b
|
||||
github.com/steambap/captcha v1.4.1
|
||||
github.com/studio-b12/gowebdav v0.0.0-20221109171924-60ec5ad56012
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5
|
||||
|
@ -387,6 +387,8 @@ github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccY
|
||||
github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c h1:DaPdLs6t6JHbedko5+w+gfNuqXgThHWkLHrKiiHrbpQ=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221131148-653b342c7b6c/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221142532-2c074735104b h1:cDjWs67Y+glYE45+HWuB2oIXWipjJaZh3mYJRpV/FNQ=
|
||||
github.com/siyuan-note/riff v0.0.0-20221221142532-2c074735104b/go.mod h1:A3G3qOTyGVOu17ui9Qg9DNkAWOgwVMxHDzHYG8sQxHc=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=
|
||||
|
@ -71,12 +71,14 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func RemoveFlashcard(blockID string, deckID string) (err error) {
|
||||
func RemoveFlashcards(deckID string, blockIDs []string) (err error) {
|
||||
deckLock.Lock()
|
||||
deck := Decks[deckID]
|
||||
deckLock.Unlock()
|
||||
|
||||
for _, blockID := range blockIDs {
|
||||
deck.RemoveCard(blockID)
|
||||
}
|
||||
err = deck.Save()
|
||||
if nil != err {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
@ -85,13 +87,15 @@ func RemoveFlashcard(blockID string, deckID string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func AddFlashcard(blockID string, deckID string) (err error) {
|
||||
func AddFlashcards(deckID string, blockIDs []string) (err error) {
|
||||
deckLock.Lock()
|
||||
deck := Decks[deckID]
|
||||
deckLock.Unlock()
|
||||
|
||||
for _, blockID := range blockIDs {
|
||||
cardID := ast.NewNodeID()
|
||||
deck.AddCard(cardID, blockID)
|
||||
}
|
||||
err = deck.Save()
|
||||
if nil != err {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
@ -128,10 +132,10 @@ func InitFlashcards() {
|
||||
}
|
||||
}
|
||||
|
||||
func CreateDeck(name string) (err error) {
|
||||
func CreateDeck(name string) (deck *riff.Deck, err error) {
|
||||
riffSavePath := getRiffDir()
|
||||
deckID := ast.NewNodeID()
|
||||
deck, err := riff.LoadDeck(riffSavePath, deckID)
|
||||
deck, err = riff.LoadDeck(riffSavePath, deckID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("load deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user