@@ -75,7 +75,53 @@ function copyToClipboard(text, button) {
7575 }
7676}
7777
78- // Setup copy button event listeners
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
79125function setupCopyButtons ( ) {
80126 // Add event listeners to all copy path buttons
81127 document
@@ -111,3 +157,23 @@ function setupCopyButtons() {
111157 } ) ;
112158 } ) ;
113159}
160+
161+ // Setup download button event listeners
162+ function setupDownloadButtons ( ) {
163+ // Add event listeners to all download buttons
164+ document
165+ . querySelectorAll ( ".download-btn, .download-btn-small" )
166+ . forEach ( ( button ) => {
167+ button . addEventListener ( "click" , function ( e ) {
168+ e . preventDefault ( ) ;
169+ e . stopPropagation ( ) ;
170+
171+ const path = this . getAttribute ( "data-path" ) ;
172+ if ( path ) {
173+ downloadFile ( path , this ) ;
174+ } else {
175+ console . error ( "No path found on download button:" , this ) ;
176+ }
177+ } ) ;
178+ } ) ;
179+ }
0 commit comments