From 0ebdd49f8afb6555e0593c8902150d346fb222ed Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 13 Apr 2023 15:47:25 +0800 Subject: [PATCH 01/10] :art: Spaced repetition interface supports review by document selection https://github.com/siyuan-note/siyuan/issues/7954 --- kernel/api/riff.go | 10 +++++++ kernel/model/flashcard.go | 57 +++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/kernel/api/riff.go b/kernel/api/riff.go index cdd2d0b99..84f8b6b2c 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -27,6 +27,16 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func getRiffCardNotebooks(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + notebooks := model.GetFlashcardNotebooks() + ret.Data = map[string]interface{}{ + "notebooks": notebooks, + } +} + func getNotebookRiffCards(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index c230b47d1..6051e6067 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -38,8 +38,53 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -var Decks = map[string]*riff.Deck{} -var deckLock = sync.Mutex{} +func GetFlashcardNotebooks() (ret []*Box) { + deck := Decks[builtinDeckID] + if nil == deck { + return + } + deckBlockIDs := deck.GetBlockIDs() + + boxes := Conf.GetOpenedBoxes() + for _, box := range boxes { + if isNotebookContainFlashcard(box.ID, deckBlockIDs) { + ret = append(ret, box) + } + } + return +} + +func isNotebookContainFlashcard(boxID string, deckBlockIDs []string) (ret bool) { + entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID)) + if nil != err { + logging.LogErrorf("read dir failed: %s", err) + return + } + + for _, entry := range entries { + if entry.IsDir() { + continue + } + + if !strings.HasSuffix(entry.Name(), ".sy") { + continue + } + + rootID := strings.TrimSuffix(entry.Name(), ".sy") + blockIDs := getTreeSubTreeChildBlocks(rootID) + for _, blockID := range deckBlockIDs { + if gulu.Str.Contains(blockID, blockIDs) { + return true + } + } + } + return +} + +var ( + Decks = map[string]*riff.Deck{} + deckLock = sync.Mutex{} +) func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, pageCount int) { blocks = []*Block{} @@ -66,9 +111,7 @@ func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, page var treeBlockIDs []string for _, rootID := range rootIDs { blockIDs := getTreeSubTreeChildBlocks(rootID) - for _, blockID := range blockIDs { - treeBlockIDs = append(treeBlockIDs, blockID) - } + treeBlockIDs = append(treeBlockIDs, blockIDs...) } treeBlockIDs = gulu.Str.RemoveDuplicatedElem(treeBlockIDs) @@ -307,9 +350,7 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl var treeBlockIDs []string for _, rootID := range rootIDs { blockIDs := getTreeSubTreeChildBlocks(rootID) - for _, blockID := range blockIDs { - treeBlockIDs = append(treeBlockIDs, blockID) - } + treeBlockIDs = append(treeBlockIDs, blockIDs...) } treeBlockIDs = gulu.Str.RemoveDuplicatedElem(treeBlockIDs) From 66bd5e91a5a5ac555c7231ee77a03f6798088fe1 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 13 Apr 2023 19:07:09 +0800 Subject: [PATCH 02/10] :art: Spaced repetition interface supports review by document selection https://github.com/siyuan-note/siyuan/issues/7954 --- kernel/api/filetree.go | 22 ++++++++--- kernel/api/notebook.go | 20 +++++++++- kernel/api/riff.go | 10 ----- kernel/model/export_merge.go | 2 +- kernel/model/file.go | 73 ++++++++++++++++++++++++++++++------ kernel/model/flashcard.go | 21 +++++++---- kernel/model/mount.go | 2 +- 7 files changed, 112 insertions(+), 38 deletions(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index c71201be4..fd0750fd6 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -95,7 +95,7 @@ func heading2Doc(c *gin.Context) { name := path.Base(targetPath) box := model.Conf.Box(targetNotebook) - files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort) + files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false) evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": box, @@ -140,7 +140,7 @@ func li2Doc(c *gin.Context) { name := path.Base(targetPath) box := model.Conf.Box(targetNotebook) - files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort) + files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false) evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": box, @@ -448,7 +448,7 @@ func createDailyNote(c *gin.Context) { evt.AppId = app name := path.Base(p) - files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort) + files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false) evt.Data = map[string]interface{}{ "box": box, "path": p, @@ -590,8 +590,13 @@ func searchDocs(c *gin.Context) { return } + flashcard := false + if arg["flashcard"] != nil { + flashcard = arg["flashcard"].(bool) + } + k := arg["k"].(string) - ret.Data = model.SearchDocsByKeyword(k) + ret.Data = model.SearchDocsByKeyword(k, flashcard) } func listDocsByPath(c *gin.Context) { @@ -610,7 +615,12 @@ func listDocsByPath(c *gin.Context) { if nil != sortParam { sortMode = int(sortParam.(float64)) } - files, totals, err := model.ListDocTree(notebook, p, sortMode) + flashcard := false + if arg["flashcard"] != nil { + flashcard = arg["flashcard"].(bool) + } + + files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard) if nil != err { ret.Code = -1 ret.Msg = err.Error() @@ -708,7 +718,7 @@ func getDoc(c *gin.Context) { func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) { evt := util.NewCmdResult("create", 0, util.PushModeBroadcast) name := path.Base(p) - files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort) + files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false) evt.Data = map[string]interface{}{ "box": box, "path": p, diff --git a/kernel/api/notebook.go b/kernel/api/notebook.go index 1f6aa153b..9e51b021a 100644 --- a/kernel/api/notebook.go +++ b/kernel/api/notebook.go @@ -308,11 +308,27 @@ func lsNotebooks(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) - notebooks, err := model.ListNotebooks() - if nil != err { + arg, ok := util.JsonArg(c, ret) + if !ok { return } + flashcard := false + if arg["flashcard"] != nil { + flashcard = arg["flashcard"].(bool) + } + + var notebooks []*model.Box + if flashcard { + notebooks = model.GetFlashcardNotebooks() + } else { + var err error + notebooks, err = model.ListNotebooks() + if nil != err { + return + } + } + ret.Data = map[string]interface{}{ "notebooks": notebooks, } diff --git a/kernel/api/riff.go b/kernel/api/riff.go index 84f8b6b2c..cdd2d0b99 100644 --- a/kernel/api/riff.go +++ b/kernel/api/riff.go @@ -27,16 +27,6 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func getRiffCardNotebooks(c *gin.Context) { - ret := gulu.Ret.NewResult() - defer c.JSON(http.StatusOK, ret) - - notebooks := model.GetFlashcardNotebooks() - ret.Data = map[string]interface{}{ - "notebooks": notebooks, - } -} - func getNotebookRiffCards(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/model/export_merge.go b/kernel/model/export_merge.go index b19aea89f..727a56fcf 100644 --- a/kernel/model/export_merge.go +++ b/kernel/model/export_merge.go @@ -110,7 +110,7 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error) } func buildBlockChildren(block *Block) (err error) { - files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort) + files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort, false) if nil != err { return } diff --git a/kernel/model/file.go b/kernel/model/file.go index af809fafe..9875562b0 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -141,9 +141,18 @@ func (box *Box) moveCorruptedData(filePath string) { logging.LogWarnf("moved corrupted data file [%s] to [%s]", filePath, to) } -func SearchDocsByKeyword(keyword string) (ret []map[string]string) { +func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]string) { ret = []map[string]string{} + var deckBlockIDs []string + if flashcard { + deck := Decks[builtinDeckID] + if nil != deck { + return + } + deckBlockIDs = deck.GetBlockIDs() + } + openedBoxes := Conf.GetOpenedBoxes() boxes := map[string]*Box{} for _, box := range openedBoxes { @@ -154,7 +163,13 @@ func SearchDocsByKeyword(keyword string) (ret []map[string]string) { if "" != keyword { for _, box := range boxes { if strings.Contains(box.Name, keyword) { - ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) + if flashcard { + if isBoxContainFlashcard(box.ID, deckBlockIDs) { + ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) + } + } else { + ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) + } } } @@ -168,17 +183,29 @@ func SearchDocsByKeyword(keyword string) (ret []map[string]string) { rootBlocks = sql.QueryRootBlockByCondition(condition) } else { for _, box := range boxes { - ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) + if flashcard { + if isBoxContainFlashcard(box.ID, deckBlockIDs) { + ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) + } + } else { + ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) + } } } - for _, block := range rootBlocks { - b := boxes[block.Box] + for _, rootBlock := range rootBlocks { + b := boxes[rootBlock.Box] if nil == b { continue } - hPath := b.Name + block.HPath - ret = append(ret, map[string]string{"path": block.Path, "hPath": hPath, "box": block.Box, "boxIcon": b.Icon}) + hPath := b.Name + rootBlock.HPath + if flashcard { + if isTreeContainFlashcard(rootBlock.ID, deckBlockIDs) { + ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon}) + } + } else { + ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon}) + } } sort.Slice(ret, func(i, j int) bool { @@ -194,7 +221,7 @@ type FileInfo struct { isdir bool } -func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err error) { +func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File, totals int, err error) { //os.MkdirAll("pprof", 0755) //cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree") //pprof.StartCPUProfile(cpuProfile) @@ -202,6 +229,15 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err ret = []*File{} + var deckBlockIDs []string + if flashcard { + deck := Decks[builtinDeckID] + if nil != deck { + return + } + deckBlockIDs = deck.GetBlockIDs() + } + box := Conf.Box(boxID) if nil == box { return nil, 0, errors.New(Conf.Language(0)) @@ -247,7 +283,15 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err } } } - docs = append(docs, doc) + + if flashcard { + rootID := strings.TrimSuffix(filepath.Base(parentDocPath), ".sy") + if isTreeContainFlashcard(rootID, deckBlockIDs) { + docs = append(docs, doc) + } + } else { + docs = append(docs, doc) + } } continue } @@ -259,8 +303,15 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err if ial := box.docIAL(file.path); nil != ial { doc := box.docFromFileInfo(file, ial) - docs = append(docs, doc) - continue + + if flashcard { + rootID := strings.TrimSuffix(filepath.Base(file.path), ".sy") + if isTreeContainFlashcard(rootID, deckBlockIDs) { + docs = append(docs, doc) + } + } else { + docs = append(docs, doc) + } } } elapsed = time.Now().Sub(start).Milliseconds() diff --git a/kernel/model/flashcard.go b/kernel/model/flashcard.go index 6051e6067..9106abb21 100644 --- a/kernel/model/flashcard.go +++ b/kernel/model/flashcard.go @@ -47,14 +47,24 @@ func GetFlashcardNotebooks() (ret []*Box) { boxes := Conf.GetOpenedBoxes() for _, box := range boxes { - if isNotebookContainFlashcard(box.ID, deckBlockIDs) { + if isBoxContainFlashcard(box.ID, deckBlockIDs) { ret = append(ret, box) } } return } -func isNotebookContainFlashcard(boxID string, deckBlockIDs []string) (ret bool) { +func isTreeContainFlashcard(rootID string, deckBlockIDs []string) (ret bool) { + blockIDs := getTreeSubTreeChildBlocks(rootID) + for _, blockID := range deckBlockIDs { + if gulu.Str.Contains(blockID, blockIDs) { + return true + } + } + return +} + +func isBoxContainFlashcard(boxID string, deckBlockIDs []string) (ret bool) { entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID)) if nil != err { logging.LogErrorf("read dir failed: %s", err) @@ -71,11 +81,8 @@ func isNotebookContainFlashcard(boxID string, deckBlockIDs []string) (ret bool) } rootID := strings.TrimSuffix(entry.Name(), ".sy") - blockIDs := getTreeSubTreeChildBlocks(rootID) - for _, blockID := range deckBlockIDs { - if gulu.Str.Contains(blockID, blockIDs) { - return true - } + if isTreeContainFlashcard(rootID, deckBlockIDs) { + return true } } return diff --git a/kernel/model/mount.go b/kernel/model/mount.go index 40eb6a6e3..491bf113f 100644 --- a/kernel/model/mount.go +++ b/kernel/model/mount.go @@ -194,7 +194,7 @@ func Mount(boxID string) (alreadyMount bool, err error) { box.Index() // 缓存根一级的文档树展开 - ListDocTree(box.ID, "/", Conf.FileTree.Sort) + ListDocTree(box.ID, "/", Conf.FileTree.Sort, false) treenode.SaveBlockTree(false) util.ClearPushProgress(100) From 1315b0e8c6ce04526e50880af6ce33a71d63569e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 13 Apr 2023 19:22:15 +0800 Subject: [PATCH 03/10] :bug: `Enter` after the folded heading in the list will cause the blocks to be reversed below the heading Fix https://github.com/siyuan-note/siyuan/issues/7984 --- kernel/treenode/heading.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/treenode/heading.go b/kernel/treenode/heading.go index 02797f45d..1f50f8597 100644 --- a/kernel/treenode/heading.go +++ b/kernel/treenode/heading.go @@ -50,8 +50,8 @@ func MoveFoldHeading(updateNode, oldNode *ast.Node) { }) for _, h := range updateFoldHeadings { children := foldHeadings[h.ID] - for _, c := range children { - h.Next.InsertAfter(c) // Next 是 Block IAL + for i := len(children) - 1; 0 <= i; i-- { + h.Next.InsertAfter(children[i]) // Next 是 Block IAL } } return From 45adb272a7fb62432a79562d6cda4c6087636aa3 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 08:49:34 +0800 Subject: [PATCH 04/10] :art: Improve editor setting font size text tip --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 545e498f3..227634add 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -548,7 +548,7 @@ "kernelFault1": "Please check if the network connection and kernel process is normal", "kernelFault2": "If the problem still occurs after restarting, please report it via GitHub Issues", "fontSize": "Font Size", - "fontSizeTip": "The default font size is 16px, this setting only affects the font size display in the editor", + "fontSizeTip": "The default font size is 16px, this setting affects the editor and exported PDF/HTML font size display", "font1": "This setting only affects the font family display in the editor, choose Default to use the theme's font family", "newNameFile": "The name of the new subdocument is", "newNameSettingFile": "The name of the new document is", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 06ad8471f..ae3716533 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -548,7 +548,7 @@ "kernelFault1": "Verifique si la conexión de red y los procesos del kernel son normales", "kernelFault2": "Si el problema sigue produciéndose después de reiniciar, comuníquelo a través de Problemas en GitHub", "fontSize": "Tamaño de la fuente", - "fontSizeTip": "El tamaño de la fuente por defecto es de 16px, este ajuste sólo afecta a la visualización del tamaño de la fuente en el editor", + "fontSizeTip": "El tamaño de fuente predeterminado es 16px, esta configuración afecta el editor y la visualización del tamaño de fuente PDF/HTML exportado", "font1": "Este ajuste sólo afecta a la visualización de la familia de fuentes en el editor, elija Por defecto para utilizar la familia de fuentes del tema", "newNameFile": "El nombre del nuevo subdocumento es", "newNameSettingFile": "El nombre del nuevo documento es", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 1cb40587a..33fa8f90a 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -548,7 +548,7 @@ "kernelFault1": "Veuillez vérifier si la connexion réseau et les processus du noyau sont normaux", "kernelFault2": "Si le problème persiste après le redémarrage, veuillez le signaler via GitHub Issues", "fontSize": "Taille de la police", - "fontSizeTip": "La taille de la police par défaut est de 16px, ce paramètre n'affecte que la taille de la police affichée dans l'éditeur.", + "fontSizeTip": "La taille de police par défaut est de 16px, ce paramètre affecte l'éditeur et l'affichage de la taille de police PDF/HTML exportée", "font1": "Ce paramètre n'affecte que l'affichage de la famille de polices dans l'éditeur, choisissez Default pour utiliser la famille de polices du thème.", "newNameFile": "Le nom du nouveau sous-document est", "newNameSettingFile": "Le nom du nouveau document est", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 9bf91c01f..4ccff5ccc 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -548,7 +548,7 @@ "kernelFault1": "請檢查網絡連接和內核進程是否正常", "kernelFault2": "如果重啟後仍然出現該問題,請通過這裡回饋", "fontSize": "字型大小", - "fontSizeTip": "字型大小預設為 16px,該設置僅影響編輯器內字體大小顯示", + "fontSizeTip": "字號默認為 16px,該設置影響編輯器和導出 PDF/HTML 字體大小顯示", "font1": "該設置僅影響編輯器內字體顯示,選擇 預設 則使用主題自帶字體", "newNameFile": "新建子文檔名為", "newNameSettingFile": "新建文檔名為", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 7861b49ad..c847b8535 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -548,7 +548,7 @@ "kernelFault1": "请检查网络连接和内核进程是否正常", "kernelFault2": "如果重启后仍然出现该问题,请通过这里反馈", "fontSize": "字号", - "fontSizeTip": "字号默认为 16px,该设置仅影响编辑器内字体大小显示", + "fontSizeTip": "字号默认为 16px,该设置影响编辑器和导出 PDF/HTML 字体大小显示", "font1": "该设置仅影响编辑器内字体显示,选择 默认 则使用主题自带字体", "newNameFile": "新建子文档名为", "newNameSettingFile": "新建文档名为", From 8fda6730a7090d1eee46e230e0c7282713646daf Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 11:38:35 +0800 Subject: [PATCH 05/10] :art: Normalize filenames when `Convert network images to local images` Fix https://github.com/siyuan-note/siyuan/issues/7992 --- kernel/model/assets.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 1ec8c338c..28e17a50f 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -107,6 +107,8 @@ func NetImg2LocalAssets(rootID, originalURL string) (err error) { } name := filepath.Base(u) + name = util.FilterFileName(name) + name = util.TruncateLenFileName(name) name = "net-img-" + name name = util.AssetName(name) writePath := filepath.Join(assetsDirPath, name) From 1e89ce45c673ea4ab3fabda5c395102afb5f6353 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 11:43:00 +0800 Subject: [PATCH 06/10] :heart: Complete open source interface and kernel #5013 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index be3f7b28e..bae94e189 100644 --- a/LICENSE +++ b/LICENSE @@ -658,4 +658,4 @@ specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see -. +. \ No newline at end of file From 0b0712f74186e2ef1f1427158a9ff6bef9176439 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 11:43:04 +0800 Subject: [PATCH 07/10] :heart: Complete open source interface and kernel #5013 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index bae94e189..be3f7b28e 100644 --- a/LICENSE +++ b/LICENSE @@ -658,4 +658,4 @@ specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see -. \ No newline at end of file +. From ee3138be6432bbb496614f7e0b95cc415f2b71e4 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 12:00:11 +0800 Subject: [PATCH 08/10] :art: API `listDocsByPath` add an optional parameter `maxListCount` Fix https://github.com/siyuan-note/siyuan/issues/7993 --- kernel/api/filetree.go | 16 ++++++++++------ kernel/model/export_merge.go | 2 +- kernel/model/file.go | 10 +++++----- kernel/model/mount.go | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index fd0750fd6..f1018838c 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -95,7 +95,7 @@ func heading2Doc(c *gin.Context) { name := path.Base(targetPath) box := model.Conf.Box(targetNotebook) - files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false) + files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount) evt := util.NewCmdResult("heading2doc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": box, @@ -140,7 +140,7 @@ func li2Doc(c *gin.Context) { name := path.Base(targetPath) box := model.Conf.Box(targetNotebook) - files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false) + files, _, _ := model.ListDocTree(targetNotebook, path.Dir(targetPath), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount) evt := util.NewCmdResult("li2doc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "box": box, @@ -448,7 +448,7 @@ func createDailyNote(c *gin.Context) { evt.AppId = app name := path.Base(p) - files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false) + files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount) evt.Data = map[string]interface{}{ "box": box, "path": p, @@ -619,14 +619,18 @@ func listDocsByPath(c *gin.Context) { if arg["flashcard"] != nil { flashcard = arg["flashcard"].(bool) } + maxListCount := model.Conf.FileTree.MaxListCount + if arg["maxListCount"] != nil { + maxListCount = int(arg["maxListCount"].(float64)) + } - files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard) + files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard, maxListCount) if nil != err { ret.Code = -1 ret.Msg = err.Error() return } - if model.Conf.FileTree.MaxListCount < totals { + if maxListCount < totals { util.PushMsg(fmt.Sprintf(model.Conf.Language(48), len(files)), 7000) } @@ -718,7 +722,7 @@ func getDoc(c *gin.Context) { func pushCreate(box *model.Box, p, treeID string, arg map[string]interface{}) { evt := util.NewCmdResult("create", 0, util.PushModeBroadcast) name := path.Base(p) - files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false) + files, _, _ := model.ListDocTree(box.ID, path.Dir(p), model.Conf.FileTree.Sort, false, model.Conf.FileTree.MaxListCount) evt.Data = map[string]interface{}{ "box": box, "path": p, diff --git a/kernel/model/export_merge.go b/kernel/model/export_merge.go index 727a56fcf..cc5443b5b 100644 --- a/kernel/model/export_merge.go +++ b/kernel/model/export_merge.go @@ -110,7 +110,7 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error) } func buildBlockChildren(block *Block) (err error) { - files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort, false) + files, _, err := ListDocTree(block.Box, block.Path, Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount) if nil != err { return } diff --git a/kernel/model/file.go b/kernel/model/file.go index 9875562b0..50c08ce8a 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -221,7 +221,7 @@ type FileInfo struct { isdir bool } -func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File, totals int, err error) { +func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount int) (ret []*File, totals int, err error) { //os.MkdirAll("pprof", 0755) //cpuProfile, _ := os.Create("pprof/cpu_profile_list_doc_tree") //pprof.StartCPUProfile(cpuProfile) @@ -363,8 +363,8 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File, return fileTreeFiles[i].Sort < fileTreeFiles[j].Sort }) ret = append(ret, fileTreeFiles...) - if Conf.FileTree.MaxListCount < len(ret) { - ret = ret[:Conf.FileTree.MaxListCount] + if maxListCount < len(ret) { + ret = ret[:maxListCount] } ret = ret[:] return @@ -390,8 +390,8 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool) (ret []*File, ret = append(ret, docs...) } - if Conf.FileTree.MaxListCount < len(ret) { - ret = ret[:Conf.FileTree.MaxListCount] + if maxListCount < len(ret) { + ret = ret[:maxListCount] } ret = ret[:] diff --git a/kernel/model/mount.go b/kernel/model/mount.go index 491bf113f..fc7d5ba1d 100644 --- a/kernel/model/mount.go +++ b/kernel/model/mount.go @@ -194,7 +194,7 @@ func Mount(boxID string) (alreadyMount bool, err error) { box.Index() // 缓存根一级的文档树展开 - ListDocTree(box.ID, "/", Conf.FileTree.Sort, false) + ListDocTree(box.ID, "/", Conf.FileTree.Sort, false, Conf.FileTree.MaxListCount) treenode.SaveBlockTree(false) util.ClearPushProgress(100) From 31e1966ffa38753e585cc0dd03eda457c9697b3a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 12:02:55 +0800 Subject: [PATCH 09/10] :art: API `listDocsByPath` add an optional parameter `maxListCount` Fix https://github.com/siyuan-note/siyuan/issues/7993 --- kernel/api/filetree.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index f1018838c..4ecc3163f 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -18,6 +18,7 @@ package api import ( "fmt" + "math" "net/http" "path" "regexp" @@ -621,7 +622,11 @@ func listDocsByPath(c *gin.Context) { } maxListCount := model.Conf.FileTree.MaxListCount if arg["maxListCount"] != nil { + // API `listDocsByPath` add an optional parameter `maxListCount` https://github.com/siyuan-note/siyuan/issues/7993 maxListCount = int(arg["maxListCount"].(float64)) + if 0 == maxListCount { + maxListCount = math.MaxInt + } } files, totals, err := model.ListDocTree(notebook, p, sortMode, flashcard, maxListCount) From e0b9002005f7a5200882da109713da03f6a61175 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Apr 2023 12:03:08 +0800 Subject: [PATCH 10/10] :art: API `listDocsByPath` add an optional parameter `maxListCount` Fix https://github.com/siyuan-note/siyuan/issues/7993 --- kernel/api/filetree.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index 4ecc3163f..c130ccbb3 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -624,7 +624,7 @@ func listDocsByPath(c *gin.Context) { if arg["maxListCount"] != nil { // API `listDocsByPath` add an optional parameter `maxListCount` https://github.com/siyuan-note/siyuan/issues/7993 maxListCount = int(arg["maxListCount"].(float64)) - if 0 == maxListCount { + if 0 >= maxListCount { maxListCount = math.MaxInt } }