MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / downloadFile

Function downloadFile

codeclash/viewer/static/js/clipboard.js:79–122  ·  view source on GitHub ↗
(filePath, button)

Source from the content-addressed store, hash-verified

77
78// Download file function
79function 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
125function setupCopyButtons() {

Callers 1

setupDownloadButtonsFunction · 0.85

Calls 2

showSuccessMessageFunction · 0.85
showErrorMessageFunction · 0.85

Tested by

no test coverage detected