@@ -172,6 +172,9 @@ function handleSuccessfulResponse(data) {
172172 // Show results section
173173 showResults ( ) ;
174174
175+ // Store the ingest_id for download functionality
176+ window . currentIngestId = data . ingest_id ;
177+
175178 // Set plain text content for summary, tree, and content
176179 document . getElementById ( 'result-summary' ) . value = data . summary || '' ;
177180 document . getElementById ( 'directory-structure-content' ) . value = data . tree || '' ;
@@ -268,33 +271,36 @@ function copyFullDigest() {
268271}
269272
270273function downloadFullDigest ( ) {
271- const summary = document . getElementById ( 'result-summary' ) . value ;
272- const directoryStructure = document . getElementById ( 'directory-structure-content' ) . value ;
273- const filesContent = document . querySelector ( '.result-text' ) . value ;
274+ // Check if we have an ingest_id
275+ if ( ! window . currentIngestId ) {
276+ console . error ( 'No ingest_id available for download' ) ;
274277
275- // Create the full content with all three sections
276- const fullContent = ` ${ summary } \n ${ directoryStructure } \n ${ filesContent } ` ;
278+ return ;
279+ }
277280
278- // Create a blob with the content
279- const blob = new Blob ( [ fullContent ] , { type : 'text/plain' } ) ;
281+ // Show feedback on the button
282+ const button = document . querySelector ( '[onclick="downloadFullDigest()"]' ) ;
283+ const originalText = button . innerHTML ;
280284
281- // Create a download link
282- const url = window . URL . createObjectURL ( blob ) ;
285+ button . innerHTML = `
286+ <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
287+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
288+ </svg>
289+ Downloading...
290+ ` ;
291+
292+ // Create a download link to the server endpoint
283293 const a = document . createElement ( 'a' ) ;
284294
285- a . href = url ;
295+ a . href = `/api/download/file/ ${ window . currentIngestId } ` ;
286296 a . download = 'digest.txt' ;
287297 document . body . appendChild ( a ) ;
288298 a . click ( ) ;
289299
290300 // Clean up
291- window . URL . revokeObjectURL ( url ) ;
292301 document . body . removeChild ( a ) ;
293302
294- // Show feedback on the button
295- const button = document . querySelector ( '[onclick="downloadFullDigest()"]' ) ;
296- const originalText = button . innerHTML ;
297-
303+ // Update button to show success
298304 button . innerHTML = `
299305 <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
300306 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
0 commit comments