(filePath, button)
| 77 | |
| 78 | // Download file function |
| 79 | function downloadFile(filePath, button) { |
| 80 | function showSuccessMessage() { |
| 81 | if (button) { |
| 82 | const originalText = button.textContent; |
| 83 | const originalColor = button.style.color; |
| 84 | button.textContent = "✓ Downloading"; |
| 85 | button.style.color = "green"; |
| 86 | setTimeout(() => { |
| 87 | button.textContent = originalText; |
| 88 | button.style.color = originalColor; |
| 89 | }, 1500); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | function showErrorMessage() { |
| 94 | if (button) { |
| 95 | const originalText = button.textContent; |
| 96 | const originalColor = button.style.color; |
| 97 | button.textContent = "✗ Failed"; |
| 98 | button.style.color = "red"; |
| 99 | setTimeout(() => { |
| 100 | button.textContent = originalText; |
| 101 | button.style.color = originalColor; |
| 102 | }, 1500); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | try { |
| 107 | // Create a temporary link element to trigger download |
| 108 | const downloadUrl = `/download-file?path=${encodeURIComponent(filePath)}`; |
| 109 | const link = document.createElement("a"); |
| 110 | link.href = downloadUrl; |
| 111 | link.style.display = "none"; |
| 112 | document.body.appendChild(link); |
| 113 | link.click(); |
| 114 | document.body.removeChild(link); |
| 115 | |
| 116 | showSuccessMessage(); |
| 117 | console.log("Downloading file:", filePath); |
| 118 | } catch (err) { |
| 119 | console.error("Failed to download file:", err); |
| 120 | showErrorMessage(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // Setup copy and download button event listeners |
| 125 | function setupCopyButtons() { |
no test coverage detected