diff --git a/frontend/components/Campaigns.tsx b/frontend/components/Campaigns.tsx index 26d9935..c018733 100755 --- a/frontend/components/Campaigns.tsx +++ b/frontend/components/Campaigns.tsx @@ -1097,6 +1097,41 @@ const ProofDetailView: React.FC<{ }); }; + const handleDownload = async () => { + const url = selectedVersion.proofPreviewUrl; + const fileName = `${proof.proofName}_V${selectedVersion.version}`; + + try { + if (url.startsWith('data:')) { + // Data URL - extract mime type and download directly + const link = document.createElement('a'); + link.href = url; + const mimeMatch = url.match(/data:([^;]+)/); + const ext = mimeMatch ? mimeMatch[1].split('/')[1] : 'png'; + link.download = `${fileName}.${ext}`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } else { + // Remote URL - fetch as blob to handle CORS and ensure download + const response = await fetch(url); + const blob = await response.blob(); + const blobUrl = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = blobUrl; + const ext = url.split('.').pop()?.split('?')[0] || 'png'; + link.download = `${fileName}.${ext}`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(blobUrl); + } + } catch (error) { + console.error('Failed to download file:', error); + alert('Sorry, there was an error downloading the file. Please try again.'); + } + }; + if (!selectedVersion) { return (
@@ -1156,7 +1191,7 @@ const ProofDetailView: React.FC<{