mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-22 16:26:09 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
0a525c0fe3
8 changed files with 60 additions and 42 deletions
|
|
@ -27,7 +27,7 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func renderRiffCard(c *gin.Context) {
|
||||
func getRiffCards(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
|
|
@ -36,16 +36,13 @@ 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)
|
||||
page := int(arg["page"].(float64))
|
||||
blockIDs, total, pageCount := model.GetFlashcards(deckID, page)
|
||||
ret.Data = map[string]interface{}{
|
||||
"content": content,
|
||||
"blockIDs": blockIDs,
|
||||
"total": total,
|
||||
"pageCount": pageCount,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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/getRiffCards", model.CheckAuth, getRiffCards)
|
||||
|
||||
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
||||
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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-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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,10 @@ 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/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=
|
||||
|
|
@ -462,8 +460,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=
|
||||
|
|
|
|||
|
|
@ -563,6 +563,8 @@ func FullReindex() {
|
|||
}
|
||||
IndexRefs()
|
||||
treenode.SaveBlockTree()
|
||||
InitFlashcards()
|
||||
|
||||
util.PushEndlessProgress(Conf.Language(58))
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
|
|
|||
|
|
@ -18,14 +18,15 @@ package model
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"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,22 +40,33 @@ 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 {
|
||||
func GetFlashcards(deckID string, page int) (blockIDs []string, total, pageCount int) {
|
||||
blockIDs = []string{}
|
||||
deck := Decks[deckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
const pageSize = 20
|
||||
var allBlockIDs []string
|
||||
for bID, _ := range deck.BlockCard {
|
||||
allBlockIDs = append(allBlockIDs, bID)
|
||||
}
|
||||
sort.Strings(allBlockIDs)
|
||||
|
||||
start := (page - 1) * pageSize
|
||||
end := page * pageSize
|
||||
if start > len(allBlockIDs) {
|
||||
return
|
||||
}
|
||||
|
||||
luteEngine := NewLute()
|
||||
if ast.NodeDocument == node.Type {
|
||||
content = luteEngine.Tree2BlockDOM(tree, luteEngine.RenderOptions)
|
||||
} else {
|
||||
content = lute.RenderNodeBlockDOM(node, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||
if end > len(allBlockIDs) {
|
||||
end = len(allBlockIDs)
|
||||
}
|
||||
blockIDs = allBlockIDs[start:end]
|
||||
total = len(allBlockIDs)
|
||||
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
||||
if 1 > len(blockIDs) {
|
||||
blockIDs = []string{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -365,7 +377,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 +414,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 +434,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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue