"use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(o,e)=>s(o,"name",{value:e,configurable:true});var g=(o,e)=>{for(var t in e)s(o,t,{get:e[t],enumerable:true})};var y=(o,e,t,i)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let n of h(e))if(!p.call(o,n)&&n!==t)s(o,n,{get:()=>e[n],enumerable:!(i=u(e,n))||i.enumerable})}return o};var v=o=>y(s({},"__esModule",{value:true}),o);var W={};g(W,{default:()=>P});module.exports=v(W);var a=require("electron");var c=require("electron-dl");var w=require("fs-extra");const l=require("../../preload-safe-debug")("Ferdium:ipcApi:download");const b=d(o=>{const e=o.match(/^data:([+/A-Za-z-]+);base64,(.+)$/);if(e?.length!==3){return new Error("Invalid input string")}return Buffer.from(e[2],"base64")},"decodeBase64Image");var P=d(o=>{a.ipcMain.on("download-file",async(e,{url:t,content:i,fileOptions:n={}})=>{const f=a.BrowserWindow.getFocusedWindow();try{if(i){try{const r=await a.dialog.showSaveDialog(o.mainWindow,{defaultPath:n.name});if(r.canceled)return;const m=b(i);(0,w.writeFileSync)(r.filePath,m,"binary");l("File blob saved to",r.filePath)}catch(r){console.error(r)}}else{const r=await(0,c.download)(f,t,{saveAs:true});l("File saved to",r.savePath)}}catch(r){console.error(r)}});a.ipcMain.handle("download-folder-select",async()=>{const e=await a.dialog.showOpenDialog(o.mainWindow,{properties:["openDirectory"]});if(e.canceled)return null;return e.filePaths[0]})},"default");
