mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-26 18:26:09 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
234ce79792
4 changed files with 72 additions and 16 deletions
|
|
@ -56,7 +56,6 @@ func getRiffDueCards(c *gin.Context) {
|
|||
}
|
||||
|
||||
deckID := arg["deckID"].(string)
|
||||
|
||||
cards, err := model.GetDueFlashcards(deckID)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
|
|
@ -113,6 +112,25 @@ func addRiffCards(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func renameRiffDeck(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
deckID := arg["deckID"].(string)
|
||||
name := arg["name"].(string)
|
||||
err := model.RenameDeck(deckID, name)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func createRiffDeck(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -300,6 +300,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/repo/openRepoSnapshotDoc", model.CheckAuth, openRepoSnapshotDoc)
|
||||
|
||||
ginServer.Handle("POST", "/api/riff/createRiffDeck", model.CheckAuth, createRiffDeck)
|
||||
ginServer.Handle("POST", "/api/riff/renameRiffDeck", model.CheckAuth, renameRiffDeck)
|
||||
ginServer.Handle("POST", "/api/riff/getRiffDecks", model.CheckAuth, getRiffDecks)
|
||||
ginServer.Handle("POST", "/api/riff/addRiffCards", model.CheckAuth, addRiffCards)
|
||||
ginServer.Handle("POST", "/api/riff/removeRiffCards", model.CheckAuth, removeRiffCards)
|
||||
|
|
|
|||
|
|
@ -812,10 +812,10 @@ func yfm(docIAL map[string]string) string {
|
|||
if "" == created {
|
||||
created = updated
|
||||
}
|
||||
buf.WriteString("created: ")
|
||||
buf.WriteString("date: ")
|
||||
buf.WriteString(created)
|
||||
buf.WriteString("\n")
|
||||
buf.WriteString("updated: ")
|
||||
buf.WriteString("lastmod: ")
|
||||
buf.WriteString(updated)
|
||||
buf.WriteString("\n")
|
||||
if "" != tags {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -46,12 +45,11 @@ func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err err
|
|||
return
|
||||
}
|
||||
|
||||
type Flashcard struct {
|
||||
ID string
|
||||
BlockID string
|
||||
}
|
||||
func GetDueFlashcards(deckID string) (ret []string, err error) {
|
||||
if "" == deckID {
|
||||
return getAllDueFlashcards()
|
||||
}
|
||||
|
||||
func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
|
||||
deckLock.Lock()
|
||||
deck := Decks[deckID]
|
||||
deckLock.Unlock()
|
||||
|
|
@ -63,10 +61,29 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
|
|||
if nil != getErr {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, &Flashcard{
|
||||
ID: card.ID(),
|
||||
BlockID: blockID,
|
||||
})
|
||||
ret = append(ret, blockID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getAllDueFlashcards() (ret []string, err error) {
|
||||
blockIDs := map[string]bool{}
|
||||
for _, deck := range Decks {
|
||||
cards := deck.Dues()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
_, getErr := GetBlock(blockID)
|
||||
if nil != getErr {
|
||||
continue
|
||||
}
|
||||
|
||||
if blockIDs[blockID] {
|
||||
continue
|
||||
}
|
||||
|
||||
ret = append(ret, blockID)
|
||||
blockIDs[blockID] = true
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -106,7 +123,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 +143,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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue