An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: New a row in the database no longer require to create a relevant doc https://github.com/siyuan-note/siyuan/issues/9294
Danielddffc277458d
diff --git a/kernel/api/filetree.go b/kernel/api/filetree.goindex c965a05dc1..3377a4a5be 100644--- a/kernel/api/filetree.go+++ b/kernel/api/filetree.go@@ -26,6 +26,7 @@ import ("unicode/utf8""github.com/88250/gulu"+ "github.com/88250/lute/ast""github.com/gin-gonic/gin""github.com/siyuan-note/siyuan/kernel/filesys""github.com/siyuan-note/siyuan/kernel/model"@@ -481,6 +482,12 @@ func createDocWithMd(c *gin.Context) {parentID = parentIDArg.(string)}+ id := ast.NewNodeID()+ idArg := arg["id"]+ if nil != idArg {+ id = idArg.(string)+ }+hPath := arg["path"].(string)markdown := arg["markdown"].(string)@@ -496,7 +503,7 @@ func createDocWithMd(c *gin.Context) {hPath = "/" + hPath}- id, err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID)+ err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID, id)if nil != err {ret.Code = -1ret.Msg = err.Error()diff --git a/kernel/model/file.go b/kernel/model/file.goindex cfd8f404c5..a73877716d 100644--- a/kernel/model/file.go+++ b/kernel/model/file.go@@ -1028,7 +1028,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Treereturn}-func CreateWithMarkdown(boxID, hPath, md, parentID string) (id string, err error) {+func CreateWithMarkdown(boxID, hPath, md, parentID, id string) (err error) {box := Conf.Box(boxID)if nil == box {err = errors.New(Conf.Language(0))@@ -1038,7 +1038,7 @@ func CreateWithMarkdown(boxID, hPath, md, parentID string) (id string, err errorWaitForWritingFiles()luteEngine := util.NewLute()dom := luteEngine.Md2BlockDOM(md, false)- id, _, err = createDocsByHPath(box.ID, hPath, dom, parentID)+ _, _, err = createDocsByHPath(box.ID, hPath, dom, parentID, id)return}@@ -1442,7 +1442,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {return}- id, existed, err := createDocsByHPath(box.ID, hPath, "", "")+ id, existed, err := createDocsByHPath(box.ID, hPath, "", "", "")if nil != err {return}diff --git a/kernel/model/path.go b/kernel/model/path.goindex ee9fe774bb..da18ea3360 100644--- a/kernel/model/path.go+++ b/kernel/model/path.go@@ -33,7 +33,7 @@ import ("github.com/siyuan-note/siyuan/kernel/util")-func createDocsByHPath(boxID, hPath, content, parentID string) (id string, existed bool, err error) {+func createDocsByHPath(boxID, hPath, content, parentID, id string /* id 参数仅在 parentID 不为空的情况下使用 */) (retID string, existed bool, err error) {hPath = strings.TrimSuffix(hPath, ".sy")pathBuilder := bytes.Buffer{}pathBuilder.WriteString("/")@@ -41,20 +41,25 @@ func createDocsByHPath(boxID, hPath, content, parentID string) (id string, existhPathBuilder.WriteString("/")if "" != parentID {- // The save path is incorrect when creating a sub-doc by ref in a doc with the same name https://github.com/siyuan-note/siyuan/issues/8138+ retID = id+ // The save path is incorrect when creating a sub-doc by ref in a doc with the same name https://github.com/siyuan-note/siyuan/issues/8138// 在指定父文档 ID 的情况下优先查找父文档parentHPath, name := path.Split(hPath)parentHPath = strings.TrimSuffix(parentHPath, "/")preferredParent := treenode.GetBlockTreeRootByHPathPreferredParentID(boxID, parentHPath, parentID)if nil != preferredParent && preferredParent.ID == parentID {// 如果父文档存在且 ID 一致,则直接在父文档下创建- id = ast.NewNodeID()p := strings.TrimSuffix(preferredParent.Path, ".sy") + "/" + id + ".sy"if _, err = createDoc(boxID, p, name, content); nil != err {return}}+ } else {+ if "" == id {+ id = ast.NewNodeID()+ retID = id+ }}parts := strings.Split(hPath, "/")[1:]@@ -64,8 +69,8 @@ func createDocsByHPath(boxID, hPath, content, parentID string) (id string, existroot := treenode.GetBlockTreeRootByHPath(boxID, hp)isNotLast := i < len(parts)-1if nil == root {- id = ast.NewNodeID()- pathBuilder.WriteString(id)+ retID = ast.NewNodeID()+ pathBuilder.WriteString(retID)docP := pathBuilder.String() + ".sy"if isNotLast {if _, err = createDoc(boxID, docP, part, ""); nil != err {@@ -85,7 +90,7 @@ func createDocsByHPath(boxID, hPath, content, parentID string) (id string, exist}}} else {- id = root.ID+ retID = root.IDpathBuilder.WriteString(root.ID)if !isNotLast {pathBuilder.WriteString(".sy")