From 06e970fb904dd6af1807ecb2bfe425e24b7afcbf Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 24 Jul 2022 22:05:14 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=AC=94=E8=AE=B0=E6=9C=AC=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AF=BC=E5=87=BA=20`.sy.zip`=20https://github.com/si?= =?UTF-8?q?yuan-note/siyuan/issues/5475?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/export.go | 16 ++++++++++++++++ kernel/api/router.go | 1 + kernel/model/export.go | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/kernel/api/export.go b/kernel/api/export.go index c8d037841..9fdefc75b 100644 --- a/kernel/api/export.go +++ b/kernel/api/export.go @@ -90,6 +90,22 @@ func exportMd(c *gin.Context) { } } +func exportNotebookSY(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + id := arg["id"].(string) + zipPath := model.ExportNotebookSY(id) + ret.Data = map[string]interface{}{ + "zip": zipPath, + } +} + func exportSY(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index 548de485d..9ce22d7a3 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -191,6 +191,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/export/batchExportMd", model.CheckAuth, batchExportMd) ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, exportMd) ginServer.Handle("POST", "/api/export/exportSY", model.CheckAuth, exportSY) + ginServer.Handle("POST", "/api/export/exportNotebookSY", model.CheckAuth, exportNotebookSY) ginServer.Handle("POST", "/api/export/exportMdContent", model.CheckAuth, exportMdContent) ginServer.Handle("POST", "/api/export/exportHTML", model.CheckAuth, exportHTML) ginServer.Handle("POST", "/api/export/exportMdHTML", model.CheckAuth, exportMdHTML) diff --git a/kernel/model/export.go b/kernel/model/export.go index 32890d654..e56b15208 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -47,6 +47,11 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func ExportNotebookSY(id string) (zipPath string) { + zipPath = exportBoxSYZip(id) + return +} + func ExportSY(id string) (name, zipPath string) { block := treenode.GetBlockTree(id) if nil == block { @@ -612,6 +617,23 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath return } +func exportBoxSYZip(boxID string) (zipPath string) { + box := Conf.Box(boxID) + if nil == box { + logging.LogErrorf("not found box [%s]", boxID) + return + } + baseFolderName := box.Name + + var docPaths []string + docFiles := box.ListFiles("/") + for _, docFile := range docFiles { + docPaths = append(docPaths, docFile.path) + } + zipPath = exportSYZip(boxID, "/", baseFolderName, docPaths) + return +} + func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (zipPath string) { dir, name := path.Split(baseFolderName) name = util.FilterFileName(name)