diff --git a/main.js b/main.js index 8096e2e..a61e67e 100644 --- a/main.js +++ b/main.js @@ -225,9 +225,22 @@ electron.ipcMain.on("file_submit", async (event, args) => { } }) -electron.ipcMain.on("file_download", async() => { - await mapFunctions.get("htmlDocumentConverter").convert({inputPath:globalFinalHtmlPath, format: globalArgs.document.outputType, showDialog: true}); -}) +ipcMain.handle("file_download", async () => { + try { + const format = globalArgs.document.outputType.replace('.', '').toLowerCase(); + + return await mapFunctions + .get("htmlDocumentConverter") + .convert({ + inputPath: globalFinalHtmlPath, + format, + showDialog: true + }); + } catch (err) { + console.error("Download failed:", err); + throw err; + } +}); electron.ipcMain.on("speaker_submit", async() => { console.log("\n\n\nJa also hier kam was an \n\n\n"); diff --git a/services/modules/convert/convert.js b/services/modules/convert/convert.js index 54b30ef..508c24f 100644 --- a/services/modules/convert/convert.js +++ b/services/modules/convert/convert.js @@ -89,7 +89,13 @@ const module_exports = { * @param {string} [options.outputName] - Optional output filename (without extension) * @param {boolean} [options.showDialog] - Show save dialog (default: false in module mode, true in CLI mode) */ - async convert({ inputPath, format = 'pdf', outputName, showDialog = false }) { +async convert({ inputPath, format = 'pdf', outputName, showDialog = false }) { + + format = format.toLowerCase().replace('.', ''); // <-- FIX + + if (!['pdf', 'docx', 'html', 'txt'].includes(format)) { + throw new Error(`Unsupported format: ${format}`); + } if (!fs.existsSync(inputPath)) { throw new Error(`Input file not found: ${inputPath}`); }