From 5f89c9a24ad116553a9af7ce734483d63db54ffd Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 21 Jul 2022 12:20:33 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/5223 --- app/src/protyle/export/index.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index a75f965d5..c52b1e85d 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -185,8 +185,8 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo }, exportResponse => { if (option.type === "word") { if (exportResponse.code === 1) { - hideMessage(msgId); showMessage(exportResponse.msg, undefined, "error"); + hideMessage(msgId); return; } afterExport(savePath, msgId); @@ -369,6 +369,26 @@ pre code { path: pdfFilePath }, () => { afterExport(pdfFilePath, msgId); + if (removeAssets) { + const removePromise = (dir: string) => { + return new Promise(function (resolve) { + //先读文件夹 + fs.stat(dir, function (err, stat) { + if (stat.isDirectory()) { + fs.readdir(dir, function (err, files) { + files = files.map(file => path.join(dir, file)); // a/b a/m + Promise.all(files.map(file => removePromise(file))).then(function () { + fs.rmdir(dir, resolve); + }); + }); + } else { + fs.unlink(dir, resolve); + } + }); + }); + }; + removePromise(path.join(filePath, "assets")); + } }); win.destroy(); }).catch((error: string) => {