Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-12-27 00:19:01 +08:00
commit 147736dda9
5 changed files with 82 additions and 31 deletions

View file

@ -150,13 +150,20 @@ func createNotebook(c *gin.Context) {
return
}
box := model.Conf.Box(id)
if nil == box {
ret.Code = -1
ret.Msg = "opened notebook [" + id + "] not found"
return
}
ret.Data = map[string]interface{}{
"notebook": model.Conf.Box(id),
"notebook": box,
}
evt := util.NewCmdResult("createnotebook", 0, util.PushModeBroadcast)
evt.Data = map[string]interface{}{
"box": model.Conf.Box(id),
"box": box,
"existed": existed,
}
util.PushEvent(evt)
@ -194,9 +201,16 @@ func openNotebook(c *gin.Context) {
return
}
box := model.Conf.Box(notebook)
if nil == box {
ret.Code = -1
ret.Msg = "opened notebook [" + notebook + "] not found"
return
}
evt := util.NewCmdResult("mount", 0, util.PushModeBroadcast)
evt.Data = map[string]interface{}{
"box": model.Conf.Box(notebook),
"box": box,
"existed": existed,
}
evt.Callback = arg["callback"]
@ -233,7 +247,13 @@ func getNotebookConf(c *gin.Context) {
return
}
box := model.Conf.Box(notebook)
box := model.Conf.GetBox(notebook)
if nil == box {
ret.Code = -1
ret.Msg = "notebook [" + notebook + "] not found"
return
}
ret.Data = map[string]interface{}{
"box": box.ID,
"name": box.Name,
@ -255,7 +275,12 @@ func setNotebookConf(c *gin.Context) {
return
}
box := model.Conf.Box(notebook)
box := model.Conf.GetBox(notebook)
if nil == box {
ret.Code = -1
ret.Msg = "notebook [" + notebook + "] not found"
return
}
param, err := gulu.JSON.MarshalJSON(arg["conf"])
if nil != err {

View file

@ -56,7 +56,7 @@ require (
github.com/siyuan-note/filelock v0.0.0-20231211015131-3b3dfabdce9c
github.com/siyuan-note/httpclient v0.0.0-20231219001541-d75e4dce39fa
github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0
github.com/siyuan-note/riff v0.0.0-20231222032533-1f1b309dbc08
github.com/siyuan-note/riff v0.0.0-20231226152006-8833f8b9a6c1
github.com/spf13/cast v1.6.0
github.com/steambap/captcha v1.4.1
github.com/studio-b12/gowebdav v0.9.0

View file

@ -366,8 +366,8 @@ github.com/siyuan-note/httpclient v0.0.0-20231219001541-d75e4dce39fa h1:kfWxJzNP
github.com/siyuan-note/httpclient v0.0.0-20231219001541-d75e4dce39fa/go.mod h1:ejS8ChupXGP89C8N4nM+xhyxVVf/IfcwOXboql6o3+g=
github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0 h1:+XjUr9UMXsczdO2bGA72p/k9wa2ShPb8ybi7CDBJ7HQ=
github.com/siyuan-note/logging v0.0.0-20231208035918-61f884c854f0/go.mod h1:6mRFtAAvYPn3cDzqvyv+t8BVPGqpONDMMb5ywOhY1D4=
github.com/siyuan-note/riff v0.0.0-20231222032533-1f1b309dbc08 h1:vPZqpEIT8gqtFM23FHbxhaCeCzccHB/KFR7OEZfAt0U=
github.com/siyuan-note/riff v0.0.0-20231222032533-1f1b309dbc08/go.mod h1:wLzj67jwt8PM+qWPGlC4V7m0fzkUlkwPKf9vLF6ru/k=
github.com/siyuan-note/riff v0.0.0-20231226152006-8833f8b9a6c1 h1:MziLTkbS4qTpeuANYEQQK5yQRSkdRXXNs+JKksbaMQk=
github.com/siyuan-note/riff v0.0.0-20231226152006-8833f8b9a6c1/go.mod h1:wLzj67jwt8PM+qWPGlC4V7m0fzkUlkwPKf9vLF6ru/k=
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=

View file

@ -649,6 +649,15 @@ func (conf *AppConf) Box(boxID string) *Box {
return nil
}
func (conf *AppConf) GetBox(boxID string) *Box {
for _, box := range conf.GetBoxes() {
if box.ID == boxID {
return box
}
}
return nil
}
func (conf *AppConf) BoxNames(boxIDs []string) (ret map[string]string) {
ret = map[string]string{}

View file

@ -390,7 +390,7 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs
delete(skipCardCache, cardID)
} else {
// 首次复习该卡片,将卡片缓存以便后续支持撤销后再次复习
reviewCardCache[cardID] = card
reviewCardCache[cardID] = card.Clone()
}
log := deck.Review(cardID, rating)
@ -404,8 +404,8 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs
return
}
dueCards, _, _, _ := getDueFlashcards(deckID, reviewedCardIDs)
if 1 > len(dueCards) {
_, unreviewedCount, _, _ := getDueFlashcards(deckID, reviewedCardIDs)
if 1 > unreviewedCount {
// 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存
reviewCardCache = map[string]riff.Card{}
skipCardCache = map[string]riff.Card{}
@ -988,7 +988,7 @@ func getDeckIDs() (deckIDs []string) {
return
}
func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCardLimit, reviewCardLimit int) (ret []riff.Card, unreviewedCount, unreviewedNewCardCount, unreviewedOldCardCount int) {
func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCardLimit, reviewCardLimit int) (ret []riff.Card, unreviewedCount, unreviewedNewCardCountInRound, unreviewedOldCardCountInRound int) {
ret = []riff.Card{}
dues := deck.Dues()
@ -1006,7 +1006,8 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar
}
dues = tmp
if 1 > len(reviewedCardIDs) {
reviewedCardCount := len(reviewedCardIDs)
if 1 > reviewedCardCount {
// 未传入已复习的卡片 ID说明是开始新的复习需要清空缓存
reviewCardCache = map[string]riff.Card{}
skipCardCache = map[string]riff.Card{}
@ -1014,11 +1015,45 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar
newCount := 0
reviewCount := 0
for _, reviewedCard := range reviewCardCache {
if riff.New == reviewedCard.GetState() {
newCount++
} else {
reviewCount++
}
}
for _, c := range dues {
if nil != skipCardCache[c.ID()] {
continue
}
if 0 < len(reviewedCardIDs) {
if !gulu.Str.Contains(c.ID(), reviewedCardIDs) {
unreviewedCount++
if riff.New == c.GetState() {
if newCount < newCardLimit {
unreviewedNewCardCountInRound++
}
} else {
if reviewCount < reviewCardLimit {
unreviewedOldCardCountInRound++
}
}
}
} else {
unreviewedCount++
if riff.New == c.GetState() {
if newCount < newCardLimit {
unreviewedNewCardCountInRound++
}
} else {
if reviewCount < reviewCardLimit {
unreviewedOldCardCountInRound++
}
}
}
if riff.New == c.GetState() {
if newCount >= newCardLimit {
continue
@ -1033,24 +1068,6 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string, newCar
reviewCount++
}
if 0 < len(reviewedCardIDs) {
if !gulu.Str.Contains(c.ID(), reviewedCardIDs) {
unreviewedCount++
if riff.New == c.GetState() {
unreviewedNewCardCount++
} else {
unreviewedOldCardCount++
}
}
} else {
unreviewedCount++
if riff.New == c.GetState() {
unreviewedNewCardCount++
} else {
unreviewedOldCardCount++
}
}
ret = append(ret, c)
}
return