mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
This commit is contained in:
parent
1b05df7d8f
commit
80197e4346
1 changed files with 49 additions and 51 deletions
|
|
@ -358,60 +358,58 @@ const initWindow = () => {
|
||||||
window.siyuan.printWin.destroy();
|
window.siyuan.printWin.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
||||||
setTimeout(() => {
|
const filePath = result.filePaths[0].endsWith(ipcData.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle));
|
||||||
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, {removeAssets: ipcData.removeAssets})));
|
||||||
const filePath = result.filePaths[0].endsWith(ipcData.rootTitle) ? result.filePaths[0] : path.join(result.filePaths[0], replaceLocalPath(ipcData.rootTitle));
|
try {
|
||||||
localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, {removeAssets: ipcData.removeAssets})));
|
window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => {
|
||||||
try {
|
fetchPost("/api/export/exportHTML", {
|
||||||
window.siyuan.printWin.webContents.printToPDF(ipcData.pdfOptions).then((pdfData) => {
|
id: ipcData.rootId,
|
||||||
fetchPost("/api/export/exportHTML", {
|
pdf: true,
|
||||||
id: ipcData.rootId,
|
removeAssets: ipcData.removeAssets,
|
||||||
pdf: true,
|
savePath: filePath
|
||||||
removeAssets: ipcData.removeAssets,
|
}, () => {
|
||||||
savePath: filePath
|
const pdfFilePath = path.join(filePath, path.basename(filePath) + ".pdf");
|
||||||
}, () => {
|
fs.writeFileSync(pdfFilePath, pdfData);
|
||||||
const pdfFilePath = path.join(filePath, path.basename(filePath) + ".pdf");
|
|
||||||
fs.writeFileSync(pdfFilePath, pdfData);
|
|
||||||
window.siyuan.printWin.destroy();
|
|
||||||
fetchPost("/api/export/addPDFOutline", {
|
|
||||||
id: ipcData.rootId,
|
|
||||||
path: pdfFilePath
|
|
||||||
}, () => {
|
|
||||||
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.rmdir(dir, resolve);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
fs.unlink(dir, resolve);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
removePromise(path.join(filePath, "assets"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).catch((error: string) => {
|
|
||||||
showMessage("Export PDF error:" + error, 0, "error", msgId);
|
|
||||||
window.siyuan.printWin.destroy();
|
window.siyuan.printWin.destroy();
|
||||||
|
fetchPost("/api/export/addPDFOutline", {
|
||||||
|
id: ipcData.rootId,
|
||||||
|
path: pdfFilePath
|
||||||
|
}, () => {
|
||||||
|
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.rmdir(dir, resolve);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fs.unlink(dir, resolve);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
removePromise(path.join(filePath, "assets"));
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
}).catch((error: string) => {
|
||||||
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
showMessage("Export PDF error:" + error, 0, "error", msgId);
|
||||||
window.siyuan.printWin.destroy();
|
window.siyuan.printWin.destroy();
|
||||||
}
|
});
|
||||||
}, 200);
|
} catch (e) {
|
||||||
|
showMessage("Export PDF failed: " + e, 0, "error", msgId);
|
||||||
|
window.siyuan.printWin.destroy();
|
||||||
|
}
|
||||||
|
window.siyuan.printWin.hide();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue