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: https://github.com/siyuan-note/siyuan/issues/13847 2
Vanessa2db18e2bb9e1
diff --git a/kernel/model/export_notebooks_test.go b/kernel/model/export_notebooks_test.goindex 6c5915bd49..2ff5d13c57 100644--- a/kernel/model/export_notebooks_test.go+++ b/kernel/model/export_notebooks_test.go@@ -162,6 +162,38 @@ func TestExportNotebooksSYKeepsCrossNotebookReferences(t *testing.T) {}}+func TestImportNotebooksSYKeepsEmptyNotebooks(t *testing.T) {+ const (+ firstBoxID = "20260817000100-box0001"+ secondBoxID = "20260817000101-box0002"+ )+ setupExportRelatedTest(t, firstBoxID, secondBoxID)+ for _, boxID := range []string{firstBoxID, secondBoxID} {+ box := &Box{ID: boxID}+ boxConf := box.GetConf()+ boxConf.Name = boxID+ if err := box.SaveConf(boxConf); nil != err {+ t.Fatal(err)+ }+ }++ exportPath := ExportNotebooksSY([]string{firstBoxID, secondBoxID})+ exportAbsPath, err := exportedFilePath(exportPath)+ if nil != err {+ t.Fatal(err)+ }+ boxIDs, bundle, err := ImportSYNotebookBundle(exportAbsPath)+ if nil != err {+ t.Fatal(err)+ }+ if !bundle {+ t.Fatal("exported archive was not detected as a notebook bundle")+ }+ if len(boxIDs) != 2 {+ t.Fatalf("imported %d notebooks, want 2", len(boxIDs))+ }+}+func openExportArchive(t *testing.T, exportPath string) *zip.ReadCloser {t.Helper()if exportPath == "" {diff --git a/kernel/model/import.go b/kernel/model/import.goindex d58070ce19..d62d76d889 100644--- a/kernel/model/import.go+++ b/kernel/model/import.go@@ -201,7 +201,7 @@ func importSY0(zipPath, boxID, toPath string, createNotebook, autoDetect bool, slogging.LogErrorf("read unzip dir [%s] failed: %s", unzipPath, err)return}- if 1 != len(entries) || !entries[0].IsDir() || len(syPaths) < 1 {+ if 1 != len(entries) || !entries[0].IsDir() {logging.LogErrorf("invalid .sy.zip [%v]", entries)err = errors.New(Conf.Language(199))return@@ -260,14 +260,20 @@ func importSY0(zipPath, boxID, toPath string, createNotebook, autoDetect bool, sreturn}}+ notebookExport := isSYNotebookExport(hasImportedBoxConf, hasImportedBoxDocMeta)+ if len(syPaths) < 1 && !notebookExport {+ logging.LogErrorf("invalid .sy.zip without documents or notebook metadata [unzipRootPath=%s]", unzipRootPath)+ err = errors.New(Conf.Language(199))+ return+ }if autoDetect {if importedMetadataErr != nil {err = errors.New(Conf.Language(199))return}- createNotebook = isSYNotebookExport(hasImportedBoxConf, hasImportedBoxDocMeta)+ createNotebook = notebookExport}- if !createNotebook && isSYNotebookExport(hasImportedBoxConf, hasImportedBoxDocMeta) {+ if !createNotebook && notebookExport {err = errors.New(Conf.Language(373))return}diff --git a/kernel/model/notebook_bundle.go b/kernel/model/notebook_bundle.goindex f67a2cf422..8293ef2fd2 100644--- a/kernel/model/notebook_bundle.go+++ b/kernel/model/notebook_bundle.go@@ -338,7 +338,8 @@ func inspectSYNotebookArchive(zipPath string) (ret *inspectedSYNotebook, err errrootPath := filepath.Join(unzipPath, entries[0].Name())ret = &inspectedSYNotebook{archivePath: zipPath, name: entries[0].Name()}confPath := filepath.Join(rootPath, ".siyuan", "conf.json")- if filelock.IsExist(confPath) {+ hasNotebookMetadata := filelock.IsExist(confPath)+ if hasNotebookMetadata {boxConf := conf.NewBoxConf()confData, readConfErr := filelock.ReadFile(confPath)if nil != readConfErr || gulu.JSON.UnmarshalJSON(confData, boxConf) != nil {@@ -350,6 +351,7 @@ func inspectSYNotebookArchive(zipPath string) (ret *inspectedSYNotebook, err err}boxDocPath := filepath.Join(rootPath, ".siyuan", boxDocMetaName)if filelock.IsExist(boxDocPath) {+ hasNotebookMetadata = truemeta := &boxDocMeta{}metaData, readMetaErr := filelock.ReadFile(boxDocPath)if nil != readMetaErr || gulu.JSON.UnmarshalJSON(metaData, meta) != nil || meta.Spec != boxDocMetaSpec || !ast.IsNodeIDPattern(meta.BoxDocID) {@@ -385,7 +387,7 @@ func inspectSYNotebookArchive(zipPath string) (ret *inspectedSYNotebook, err err})return nil})- if nil != err || syCount < 1 {+ if nil != err || (syCount < 1 && !hasNotebookMetadata) {return nil, errors.New(Conf.Language(199))}for blockID := range seenBlockIDs {