浏览代码

:art: 浏览器端和移动端导出 Data 去掉 `data-` 前缀 Fix https://github.com/siyuan-note/siyuan/issues/6808
导出 Data 不带 data 父文件夹 Fix https://github.com/siyuan-note/siyuan/issues/6805

Liang Ding 2 年之前
父节点
当前提交
ae11242a19
共有 3 个文件被更改,包括 27 次插入23 次删除
  1. 16 14
      app/src/config/exportConfig.ts
  2. 4 1
      kernel/api/export.go
  3. 7 8
      kernel/model/export.go

+ 16 - 14
app/src/config/exportConfig.ts

@@ -1,8 +1,9 @@
 import {fetchPost} from "../util/fetch";
 /// #if !BROWSER
 import {dialog} from "@electron/remote";
-import {SaveDialogReturnValue, shell} from "electron";
+import {shell} from "electron";
 import {afterExport} from "../protyle/export/util";
+import * as path from "path";
 /// #endif
 import {isBrowser} from "../util/functions";
 import {showMessage} from "../dialog/message";
@@ -157,19 +158,20 @@ export const exportConfig = {
                 window.location.href = response.data.zip;
             });
             /// #else
-            dialog.showSaveDialog({
-                defaultPath: "data",
-                properties: ["showOverwriteConfirmation"],
-            }).then((result: SaveDialogReturnValue) => {
-                if (!result.canceled) {
-                    const msgId = showMessage(window.siyuan.languages.exporting, -1);
-                    fetchPost("/api/export/exportDataInFolder", {
-                        folder: result.filePath
-                    }, () => {
-                        afterExport(result.filePath, msgId);
-                    });
-                }
-            });
+            let filePaths = dialog.showOpenDialogSync({
+                title: window.siyuan.languages.export + " " + "Data",
+                properties: ["createDirectory", "openDirectory"],
+            })
+            if (filePaths && 0 < filePaths.length) {
+                const savePath = filePaths[0];
+                const msgId = showMessage(window.siyuan.languages.exporting, -1);
+                fetchPost("/api/export/exportDataInFolder", {
+                    folder: savePath,
+                }, response => {
+                    afterExport(path.join(savePath, response.data.name), msgId);
+                });
+            }
+
             /// #endif
         });
         /// #if !BROWSER

+ 4 - 1
kernel/api/export.go

@@ -41,13 +41,16 @@ func exportDataInFolder(c *gin.Context) {
 	}
 
 	exportFolder := arg["folder"].(string)
-	err := model.ExportDataInFolder(exportFolder)
+	name, err := model.ExportDataInFolder(exportFolder)
 	if nil != err {
 		ret.Code = -1
 		ret.Msg = err.Error()
 		ret.Data = map[string]interface{}{"closeTimeout": 7000}
 		return
 	}
+	ret.Data = map[string]interface{}{
+		"name": name,
+	}
 }
 
 func exportData(c *gin.Context) {

+ 7 - 8
kernel/model/export.go

@@ -120,17 +120,18 @@ func ExportSY(id string) (name, zipPath string) {
 	return
 }
 
-func ExportDataInFolder(exportFolder string) (err error) {
+func ExportDataInFolder(exportFolder string) (name string, err error) {
 	util.PushEndlessProgress(Conf.Language(65))
 	defer util.ClearPushProgress(100)
 
 	WaitForWritingFiles()
 
 	exportFolder = filepath.Join(exportFolder, util.CurrentTimeSecondsStr())
-	err = exportData(exportFolder)
+	zipPath, err := exportData(exportFolder)
 	if nil != err {
 		return
 	}
+	name = filepath.Base(zipPath)
 	return
 }
 
@@ -140,10 +141,8 @@ func ExportData() (zipPath string) {
 
 	WaitForWritingFiles()
 
-	baseFolderName := "data-" + util.CurrentTimeSecondsStr()
-	exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
-	zipPath = exportFolder + ".zip"
-	err := exportData(exportFolder)
+	exportFolder := filepath.Join(util.TempDir, "export", util.CurrentTimeSecondsStr())
+	zipPath, err := exportData(exportFolder)
 	if nil != err {
 		return
 	}
@@ -151,7 +150,7 @@ func ExportData() (zipPath string) {
 	return
 }
 
-func exportData(exportFolder string) (err error) {
+func exportData(exportFolder string) (zipPath string, err error) {
 	baseFolderName := "data-" + util.CurrentTimeSecondsStr()
 	if err = os.MkdirAll(exportFolder, 0755); nil != err {
 		logging.LogErrorf("create export temp folder failed: %s", err)
@@ -165,7 +164,7 @@ func exportData(exportFolder string) (err error) {
 		return
 	}
 
-	zipPath := exportFolder + ".zip"
+	zipPath = exportFolder + ".zip"
 	zip, err := gulu.Zip.Create(zipPath)
 	if nil != err {
 		logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)