From 3dd84974e20ba47d58f66170f11904f92f81b665 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 16:41:30 +0800 Subject: [PATCH 01/10] =?UTF-8?q?:arrow=5Fup:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 6 +++--- kernel/go.sum | 16 ++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index 9e32ff760..9a1949ab4 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -39,7 +39,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 github.com/shirou/gopsutil/v3 v3.22.11 - github.com/siyuan-note/dejavu v0.0.0-20221224123234-85f7639a2dc3 + github.com/siyuan-note/dejavu v0.0.0-20221229083812-ad1889a03191 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e @@ -62,7 +62,7 @@ require ( github.com/alecthomas/chroma v0.10.0 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect - github.com/aws/aws-sdk-go v1.44.167 // indirect + github.com/aws/aws-sdk-go v1.44.169 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/dsnet/compress v0.0.1 // indirect @@ -121,7 +121,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/crypto v0.4.0 // indirect - golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 // indirect + golang.org/x/exp v0.0.0-20221227203929-1b447090c38c // indirect golang.org/x/mod v0.7.0 // indirect golang.org/x/net v0.4.0 // indirect golang.org/x/sync v0.1.0 // indirect diff --git a/kernel/go.sum b/kernel/go.sum index 3dc696792..edbd7dd05 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -17,10 +17,6 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798 h1:sR/s/Y9wyl79ZRCUERwLPo9zqaB3KhNRodCMTJ4ozEU= github.com/88250/gulu v1.2.3-0.20221117052724-cd06804db798/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI= -github.com/88250/lute v1.7.5-0.20221228082840-f51571fe01c5 h1:TAfGEgAW0OMzwNIxvhnNrpwTgmKyQDlBZI8zg1CUqK0= -github.com/88250/lute v1.7.5-0.20221228082840-f51571fe01c5/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA= -github.com/88250/lute v1.7.5-0.20221228084920-dff461f9283f h1:WQZK9EER7keZLK9o6fTK5k4jcTiDpcZmyMyaOv4isV4= -github.com/88250/lute v1.7.5-0.20221228084920-dff461f9283f/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA= github.com/88250/lute v1.7.5-0.20221228091547-322f538d4f33 h1:2A3pQE3Av78X690Q0deDMpT31ytc7PGIt4TNDBRlD9A= github.com/88250/lute v1.7.5-0.20221228091547-322f538d4f33/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA= github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q= @@ -50,8 +46,8 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII= -github.com/aws/aws-sdk-go v1.44.167 h1:kQmBhGdZkQLU7AiHShSkBJ15zr8agy0QeaxXduvyp2E= -github.com/aws/aws-sdk-go v1.44.167/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go v1.44.169 h1:+UAazxZwfcuCVtJ6LVR1hX+EJW6BPsFFAZERhOtFNrM= +github.com/aws/aws-sdk-go v1.44.169/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= @@ -377,8 +373,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= -github.com/siyuan-note/dejavu v0.0.0-20221224123234-85f7639a2dc3 h1:5EUSt8tFYzPydUTmr5JhDJexW/kQ6Y6RStsaWompkbI= -github.com/siyuan-note/dejavu v0.0.0-20221224123234-85f7639a2dc3/go.mod h1:bemsV89S70xPIoY6CX9SkL3IX6YkCwS8nK09KTKg/S4= +github.com/siyuan-note/dejavu v0.0.0-20221229083812-ad1889a03191 h1:WofLVK8o6+MKkGMmqX7RwPEgafVCXbpt0XjiLuC5rp8= +github.com/siyuan-note/dejavu v0.0.0-20221229083812-ad1889a03191/go.mod h1:bemsV89S70xPIoY6CX9SkL3IX6YkCwS8nK09KTKg/S4= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90= @@ -462,8 +458,8 @@ golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= -golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 h1:5oN1Pz/eDhCpbMbLstvIPa0b/BEQo6g6nwV3pLjfM6w= -golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20221227203929-1b447090c38c h1:Govq2W3bnHJimHT2ium65kXcI7ZzTniZHcFATnLJM0Q= +golang.org/x/exp v0.0.0-20221227203929-1b447090c38c/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20190823064033-3a9bac650e44/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= From 28ad679f1f6298d488992bb1556581ad4f465547 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 19:41:47 +0800 Subject: [PATCH 02/10] :art: Clean code --- kernel/bazaar/package.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bazaar/package.go b/kernel/bazaar/package.go index 77cc0d3cb..616d1c644 100644 --- a/kernel/bazaar/package.go +++ b/kernel/bazaar/package.go @@ -308,7 +308,7 @@ func downloadPackage(repoURLHash string, pushProgress bool, systemID string) (da resp, err := httpclient.NewBrowserRequest().SetOutput(buf).SetDownloadCallback(func(info req.DownloadInfo) { if pushProgress { progress := float32(info.DownloadedSize) / float32(info.Response.ContentLength) - logging.LogDebugf("downloading bazaar package [%d]", progress) + //logging.LogDebugf("downloading bazaar package [%f]", progress) util.PushDownloadProgress(pushID, progress) } }).Get(u) From e95701a3f48ae28162dc3cfe18428227610cb767 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 19:47:29 +0800 Subject: [PATCH 03/10] =?UTF-8?q?:arrow=5Fup:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 2 +- kernel/go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/go.mod b/kernel/go.mod index 9a1949ab4..efea6313e 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -39,7 +39,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 github.com/shirou/gopsutil/v3 v3.22.11 - github.com/siyuan-note/dejavu v0.0.0-20221229083812-ad1889a03191 + github.com/siyuan-note/dejavu v0.0.0-20221229113641-896a1a87254c github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e diff --git a/kernel/go.sum b/kernel/go.sum index edbd7dd05..ac559a54c 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -375,6 +375,8 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYED github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/siyuan-note/dejavu v0.0.0-20221229083812-ad1889a03191 h1:WofLVK8o6+MKkGMmqX7RwPEgafVCXbpt0XjiLuC5rp8= github.com/siyuan-note/dejavu v0.0.0-20221229083812-ad1889a03191/go.mod h1:bemsV89S70xPIoY6CX9SkL3IX6YkCwS8nK09KTKg/S4= +github.com/siyuan-note/dejavu v0.0.0-20221229113641-896a1a87254c h1:S3NF9QCkBNf58MPHyneClR4wOBdm/bVN4q4AX7+biPo= +github.com/siyuan-note/dejavu v0.0.0-20221229113641-896a1a87254c/go.mod h1:bemsV89S70xPIoY6CX9SkL3IX6YkCwS8nK09KTKg/S4= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90= From 7797750ae8e5967fc4622c3f019fb8433c345cbe Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 19:49:14 +0800 Subject: [PATCH 04/10] =?UTF-8?q?:art:=20=E9=87=8D=E5=BB=BA=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E6=97=B6=20reload=20=E9=97=AA=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/box.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/model/box.go b/kernel/model/box.go index 5c96c97aa..f8a495525 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -563,6 +563,8 @@ func FullReindex() { } IndexRefs() treenode.SaveBlockTree() + InitFlashcards() + util.PushEndlessProgress(Conf.Language(58)) go func() { time.Sleep(1 * time.Second) From c4ba046898902cabecb7e5fe8dda1e69f6c779c9 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 20:57:16 +0800 Subject: [PATCH 05/10] =?UTF-8?q?:bug:=20=E9=BB=98=E8=AE=A4=E9=97=AA?= =?UTF-8?q?=E5=8D=A1=E5=8C=85=E7=A7=BB=E9=99=A4=E5=90=8E=E5=8D=A1=E4=BD=8F?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/6946?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 14 ++++---------- kernel/api/router.go | 2 +- kernel/model/flashcard.go | 37 ++++++++++++++----------------------- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 89b5307ea..9d2ea5fa2 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -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, } } diff --git a/kernel/api/router.go b/kernel/api/router.go index 12c161f65..f65db1623 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -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) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index dc2d75603..09bcdfe27 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -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,12 +385,17 @@ func RemoveDeck(deckID string) (err error) { riffSavePath := getRiffDir() deckPath := filepath.Join(riffSavePath, deckID+".deck") - if err = os.Remove(deckPath); nil != err { - return + if gulu.File.IsExist(deckPath) { + if err = os.Remove(deckPath); nil != err { + return + } } + cardsPath := filepath.Join(riffSavePath, deckID+".cards") - if err = os.Remove(cardsPath); nil != err { - return + if gulu.File.IsExist(cardsPath) { + if err = os.Remove(cardsPath); nil != err { + return + } } InitFlashcards() @@ -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 From 7d450f88eb58d1616339ce9f270a7152c16d0f86 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 21:46:35 +0800 Subject: [PATCH 06/10] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=8D=A1=E5=8C=85=E5=86=85=E7=9A=84=E9=97=AA=E5=8D=A1?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6943?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 5 +++-- kernel/api/router.go | 2 +- kernel/model/flashcard.go | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 9d2ea5fa2..fb8bc54f0 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -27,7 +27,7 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func searchRiffCards(c *gin.Context) { +func getRiffCards(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) @@ -37,7 +37,8 @@ func searchRiffCards(c *gin.Context) { } deckID := arg["deckID"].(string) - blockIDs := model.SearchFlashcard(deckID) + page := int(arg["page"].(float64)) + blockIDs := model.GetFlashcards(deckID, page) ret.Data = map[string]interface{}{ "blockIDs": blockIDs, } diff --git a/kernel/api/router.go b/kernel/api/router.go index f65db1623..cb3bf3d5d 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -308,7 +308,7 @@ func ServeAPI(ginServer *gin.Engine) { 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) - ginServer.Handle("POST", "/api/riff/searchRiffCards", model.CheckAuth, searchRiffCards) + ginServer.Handle("POST", "/api/riff/getRiffCards", model.CheckAuth, getRiffCards) ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg) ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 09bcdfe27..4d45ad4d8 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -20,6 +20,7 @@ import ( "errors" "os" "path/filepath" + "sort" "strings" "sync" "time" @@ -38,7 +39,27 @@ import ( var Decks = map[string]*riff.Deck{} var deckLock = sync.Mutex{} -func SearchFlashcard(deckID string) (blockIDs []string) { +func GetFlashcards(deckID string, page int) (blockIDs []string) { + deck := Decks[deckID] + if nil == deck { + return + } + + var allBlockIDs []string + for bID, _ := range deck.BlockCard { + allBlockIDs = append(allBlockIDs, bID) + } + sort.Strings(allBlockIDs) + + start := (page - 1) * 20 + end := page * 20 + if start > len(allBlockIDs) { + return + } + if end > len(allBlockIDs) { + end = len(allBlockIDs) + } + blockIDs = allBlockIDs[start:end] return } From 38570cb27fedafeb3d7f2e006d562084cc6829eb Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 21:52:36 +0800 Subject: [PATCH 07/10] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=8D=A1=E5=8C=85=E5=86=85=E7=9A=84=E9=97=AA=E5=8D=A1?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6943?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/riff.go | 6 ++++-- kernel/model/flashcard.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index fb8bc54f0..3841a2815 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -38,9 +38,11 @@ func getRiffCards(c *gin.Context) { deckID := arg["deckID"].(string) page := int(arg["page"].(float64)) - blockIDs := model.GetFlashcards(deckID, page) + blockIDs, total, pageCount := model.GetFlashcards(deckID, page) ret.Data = map[string]interface{}{ - "blockIDs": blockIDs, + "blockIDs": blockIDs, + "total": total, + "pageCount": pageCount, } } diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 4d45ad4d8..c292b9b0d 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -39,7 +39,7 @@ import ( var Decks = map[string]*riff.Deck{} var deckLock = sync.Mutex{} -func GetFlashcards(deckID string, page int) (blockIDs []string) { +func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount int) { deck := Decks[deckID] if nil == deck { return @@ -60,6 +60,8 @@ func GetFlashcards(deckID string, page int) (blockIDs []string) { end = len(allBlockIDs) } blockIDs = allBlockIDs[start:end] + total = len(allBlockIDs) + pageCount = total / 20 return } From b999d293d5ffd80e2daae0414ead236175e9ae69 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 21:54:10 +0800 Subject: [PATCH 08/10] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=8D=A1=E5=8C=85=E5=86=85=E7=9A=84=E9=97=AA=E5=8D=A1?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6943?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/flashcard.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index c292b9b0d..8051c8c17 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -18,6 +18,7 @@ package model import ( "errors" + "math" "os" "path/filepath" "sort" @@ -45,14 +46,15 @@ func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount return } + const pageSize = 20 var allBlockIDs []string for bID, _ := range deck.BlockCard { allBlockIDs = append(allBlockIDs, bID) } sort.Strings(allBlockIDs) - start := (page - 1) * 20 - end := page * 20 + start := (page - 1) * pageSize + end := page * pageSize if start > len(allBlockIDs) { return } @@ -61,7 +63,7 @@ func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount } blockIDs = allBlockIDs[start:end] total = len(allBlockIDs) - pageCount = total / 20 + pageCount = int(math.Ceil(float64(total) / float64(pageSize))) return } From 192679eeddef118a2257b8259bc8c7f09d087f57 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 22:00:07 +0800 Subject: [PATCH 09/10] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=8D=A1=E5=8C=85=E5=86=85=E7=9A=84=E9=97=AA=E5=8D=A1?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6943?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/flashcard.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 8051c8c17..6c6c3f211 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -41,6 +41,7 @@ var Decks = map[string]*riff.Deck{} var deckLock = sync.Mutex{} func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount int) { + blockIDs = []string{} deck := Decks[deckID] if nil == deck { return @@ -64,6 +65,9 @@ func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount blockIDs = allBlockIDs[start:end] total = len(allBlockIDs) pageCount = int(math.Ceil(float64(total) / float64(pageSize))) + if 1 > len(blockIDs) { + blockIDs = []string{} + } return } From e06d774da0abf9e2f78c72fe3c92e4b8f1139ce2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 29 Dec 2022 22:48:06 +0800 Subject: [PATCH 10/10] =?UTF-8?q?:art:=20=E5=B0=9D=E8=AF=95=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=BD=9C=E5=9C=A8=E7=9A=84=E5=89=AA=E8=97=8F=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E8=AF=B7=E6=B1=82=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20https://github.com/siyuan-note/siyuan/issues/6907?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/server/serve.go | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/server/serve.go b/kernel/server/serve.go index 8bd5ae71c..382f16a0e 100644 --- a/kernel/server/serve.go +++ b/kernel/server/serve.go @@ -474,6 +474,7 @@ func corsMiddleware() gin.HandlerFunc { c.Header("Access-Control-Allow-Credentials", "true") c.Header("Access-Control-Allow-Headers", "origin, Content-Length, Content-Type, Authorization") c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS") + c.Header("Access-Control-Allow-Private-Network", "true") if c.Request.Method == "OPTIONS" { c.AbortWithStatus(204)