2 lines
1.5 KiB
JavaScript
2 lines
1.5 KiB
JavaScript
import{j as a,v as p}from"./vendor-BKmmeuxg.js";import{B as w}from"./button-BpNwv2aE.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";const k=({backup:s})=>{const i=async n=>{var l;try{const o=document.getElementById(`download-btn-${n}`);o&&(o.innerHTML='<span class="animate-spin mr-1">↻</span> Downloading...');const t=await fetch(`/system/backup/${n}/download`,{method:"GET",headers:{Accept:"application/zip","X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":((l=document.querySelector('meta[name="csrf-token"]'))==null?void 0:l.getAttribute("content"))||""}});if(!t.ok)throw new Error("Download failed");const d=t.headers.get("content-disposition"),c=d?d.split("filename=")[1].replace(/"/g,""):`backup_${n}.zip`,m=await t.blob(),r=window.URL.createObjectURL(m),e=document.createElement("a");e.href=r,e.download=c,document.body.appendChild(e),e.click(),window.URL.revokeObjectURL(r),document.body.removeChild(e)}catch(o){console.error("Download failed:",o),alert("Failed to download backup. Please try again.")}finally{const o=document.getElementById(`download-btn-${n}`);o&&(o.innerHTML='<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/></svg><span class="ml-1">Download</span>')}};return a.jsxs(w,{id:`download-btn-${s.id}`,variant:"ghost",onClick:()=>i(s.id),children:[a.jsx(p,{className:"h-4 w-4"}),a.jsx("span",{className:"text-sm",children:"Download"})]})};export{k as default};
|