Animation added

This commit is contained in:
2025-11-20 23:38:31 -05:00
parent 9197e464a5
commit cf010974dd
8 changed files with 304 additions and 22 deletions

View File

@@ -131,9 +131,39 @@ async function downloadMaze() {
}
try {
window.open(`${API_BASE}/download/${currentMazeId}?solution=false`, '_blank');
showSuccess('Downloading maze image...');
// Create a temporary link and trigger download
const downloadUrl = `${API_BASE}/download/${currentMazeId}?solution=false&format=png`;
const response = await fetch(downloadUrl);
if (!response.ok) {
const errorData = await response.json().catch(() => ({ error: 'Download failed' }));
throw new Error(errorData.error || `Server returned ${response.status}`);
}
const blob = await response.blob();
// Verify we got an image
if (!blob.type.startsWith('image/')) {
throw new Error('Invalid response: not an image');
}
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `maze_${currentMazeId}_${currentMazeData.algorithm.replace(/[^a-z0-9]/gi, '_')}.png`;
document.body.appendChild(a);
a.click();
// Clean up after a short delay
setTimeout(() => {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 100);
showSuccess('Maze image downloaded!');
} catch (error) {
console.error('Download error:', error);
showError('Failed to download: ' + error.message);
}
}