Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Remove empty assets dir when exporting PDF https://github.com/siyuan-note/siyuan/issues/13670

Danielfa27f6c33fdf
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index 1f3002e6a5..41e9d5f413 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -322,29 +322,35 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
path: pdfFilePath,
removeAssets: ipcData.removeAssets,
watermark: ipcData.watermark
- }, () => {
+ }, async () => {
afterExport(pdfFilePath, msgId);
if (ipcData.removeAssets) {
const removePromise = (dir: string) => {
return new Promise(function (resolve) {
- //先读文件夹
fs.stat(dir, function (err, stat) {
- if (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.rm(dir, resolve);
- });
+ if (!stat) {
+ return;
+ }
+
+ 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.rm(dir, resolve);
});
- } else {
- fs.unlink(dir, resolve);
- }
+ });
+ } else {
+ fs.unlink(dir, resolve);
}
});
});
};
- removePromise(path.join(savePath, "assets"));
+
+ const assetsDir = path.join(savePath, "assets");
+ await removePromise(assetsDir);
+ if (1 > fs.readdirSync(assetsDir).length) {
+ fs.rmdirSync(assetsDir);
+ }
}
});
});