An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: New default appearance icon https://github.com/siyuan-note/siyuan/issues/7976
Daniel20cbd21b7a38
diff --git a/kernel/cli/cmd/import.go b/kernel/cli/cmd/import.gonew file mode 100644index 0000000000..54ffb7f7fd--- /dev/null+++ b/kernel/cli/cmd/import.go@@ -0,0 +1,130 @@+// SiYuan - Refactor your thinking+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package cmd++import (+ "fmt"+ "path/filepath"++ "github.com/siyuan-note/siyuan/kernel/model"++ "github.com/spf13/cobra"+)++var importCmd = &cobra.Command{+ Use: "import",+ Short: "Import files",+}++var importMdCmd = &cobra.Command{+ Use: "md --file <path> --notebook <id>",+ Short: "Import Markdown file or directory",+ RunE: func(cmd *cobra.Command, args []string) error {+ filePath, _ := cmd.Flags().GetString("file")+ notebook, _ := cmd.Flags().GetString("notebook")+ toPath, _ := cmd.Flags().GetString("path")+ if filePath == "" {+ return fmt.Errorf("--file is required")+ }+ if notebook == "" {+ return fmt.Errorf("--notebook is required")+ }+ if toPath == "" {+ toPath = "/"+ }++ absPath, err := filepath.Abs(filePath)+ if err != nil {+ return err+ }++ if err := model.ImportFromLocalPath(notebook, absPath, toPath); err != nil {+ return err+ }+ fmt.Println("ok")+ return nil+ },+}++var importSYCmd = &cobra.Command{+ Use: "sy --file <path> --notebook <id>",+ Short: "Import .sy.zip archive",+ RunE: func(cmd *cobra.Command, args []string) error {+ filePath, _ := cmd.Flags().GetString("file")+ notebook, _ := cmd.Flags().GetString("notebook")+ toPath, _ := cmd.Flags().GetString("path")+ if filePath == "" {+ return fmt.Errorf("--file is required")+ }+ if notebook == "" {+ return fmt.Errorf("--notebook is required")+ }+ if toPath == "" {+ toPath = "/"+ }++ absPath, err := filepath.Abs(filePath)+ if err != nil {+ return err+ }++ if err := model.ImportSY(absPath, notebook, toPath); err != nil {+ return err+ }+ fmt.Println("ok")+ return nil+ },+}++var importDataCmd = &cobra.Command{+ Use: "data --file <path>",+ Short: "Import data backup",+ RunE: func(cmd *cobra.Command, args []string) error {+ filePath, _ := cmd.Flags().GetString("file")+ if filePath == "" {+ return fmt.Errorf("--file is required")+ }++ absPath, err := filepath.Abs(filePath)+ if err != nil {+ return err+ }++ if err := model.ImportData(absPath); err != nil {+ return err+ }+ fmt.Println("ok")+ return nil+ },+}++func init() {+ importMdCmd.Flags().String("file", "", "file or directory path")+ importMdCmd.Flags().StringP("notebook", "n", "", "notebook ID")+ importMdCmd.Flags().String("path", "", "target path (default /)")++ importSYCmd.Flags().String("file", "", ".sy.zip file path")+ importSYCmd.Flags().StringP("notebook", "n", "", "notebook ID")+ importSYCmd.Flags().String("path", "", "target path (default /)")++ importDataCmd.Flags().String("file", "", "data backup zip path")++ rootCmd.AddCommand(importCmd)+ importCmd.AddCommand(importMdCmd)+ importCmd.AddCommand(importSYCmd)+ importCmd.AddCommand(importDataCmd)+}