mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 06:11:24 +08:00
🎨 浏览器端和移动端导出 Data 去掉 data-
前缀 Fix https://github.com/siyuan-note/siyuan/issues/6808
导出 Data 不带 data 父文件夹 Fix https://github.com/siyuan-note/siyuan/issues/6805
This commit is contained in:
parent
560ff8c9d4
commit
ae11242a19
@ -1,8 +1,9 @@
|
|||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {dialog} from "@electron/remote";
|
import {dialog} from "@electron/remote";
|
||||||
import {SaveDialogReturnValue, shell} from "electron";
|
import {shell} from "electron";
|
||||||
import {afterExport} from "../protyle/export/util";
|
import {afterExport} from "../protyle/export/util";
|
||||||
|
import * as path from "path";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {isBrowser} from "../util/functions";
|
import {isBrowser} from "../util/functions";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
@ -157,19 +158,20 @@ export const exportConfig = {
|
|||||||
window.location.href = response.data.zip;
|
window.location.href = response.data.zip;
|
||||||
});
|
});
|
||||||
/// #else
|
/// #else
|
||||||
dialog.showSaveDialog({
|
let filePaths = dialog.showOpenDialogSync({
|
||||||
defaultPath: "data",
|
title: window.siyuan.languages.export + " " + "Data",
|
||||||
properties: ["showOverwriteConfirmation"],
|
properties: ["createDirectory", "openDirectory"],
|
||||||
}).then((result: SaveDialogReturnValue) => {
|
})
|
||||||
if (!result.canceled) {
|
if (filePaths && 0 < filePaths.length) {
|
||||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
const savePath = filePaths[0];
|
||||||
fetchPost("/api/export/exportDataInFolder", {
|
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
||||||
folder: result.filePath
|
fetchPost("/api/export/exportDataInFolder", {
|
||||||
}, () => {
|
folder: savePath,
|
||||||
afterExport(result.filePath, msgId);
|
}, response => {
|
||||||
});
|
afterExport(path.join(savePath, response.data.name), msgId);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
/// #endif
|
/// #endif
|
||||||
});
|
});
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
@ -41,13 +41,16 @@ func exportDataInFolder(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exportFolder := arg["folder"].(string)
|
exportFolder := arg["folder"].(string)
|
||||||
err := model.ExportDataInFolder(exportFolder)
|
name, err := model.ExportDataInFolder(exportFolder)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"name": name,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportData(c *gin.Context) {
|
func exportData(c *gin.Context) {
|
||||||
|
@ -120,17 +120,18 @@ func ExportSY(id string) (name, zipPath string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExportDataInFolder(exportFolder string) (err error) {
|
func ExportDataInFolder(exportFolder string) (name string, err error) {
|
||||||
util.PushEndlessProgress(Conf.Language(65))
|
util.PushEndlessProgress(Conf.Language(65))
|
||||||
defer util.ClearPushProgress(100)
|
defer util.ClearPushProgress(100)
|
||||||
|
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
|
|
||||||
exportFolder = filepath.Join(exportFolder, util.CurrentTimeSecondsStr())
|
exportFolder = filepath.Join(exportFolder, util.CurrentTimeSecondsStr())
|
||||||
err = exportData(exportFolder)
|
zipPath, err := exportData(exportFolder)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
name = filepath.Base(zipPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,10 +141,8 @@ func ExportData() (zipPath string) {
|
|||||||
|
|
||||||
WaitForWritingFiles()
|
WaitForWritingFiles()
|
||||||
|
|
||||||
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
exportFolder := filepath.Join(util.TempDir, "export", util.CurrentTimeSecondsStr())
|
||||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
zipPath, err := exportData(exportFolder)
|
||||||
zipPath = exportFolder + ".zip"
|
|
||||||
err := exportData(exportFolder)
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -151,7 +150,7 @@ func ExportData() (zipPath string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportData(exportFolder string) (err error) {
|
func exportData(exportFolder string) (zipPath string, err error) {
|
||||||
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
||||||
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
||||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||||
@ -165,7 +164,7 @@ func exportData(exportFolder string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
zipPath := exportFolder + ".zip"
|
zipPath = exportFolder + ".zip"
|
||||||
zip, err := gulu.Zip.Create(zipPath)
|
zip, err := gulu.Zip.Create(zipPath)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user