mirror of
				https://github.com/Frooodle/Stirling-PDF.git
				synced 2025-11-01 01:21:18 +01:00 
			
		
		
		
	Fixed #74 (visual feedback of downloads)
This commit is contained in:
		
							parent
							
								
									b100435d9c
								
							
						
					
					
						commit
						a342def43f
					
				@ -208,7 +208,7 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
<th:block th:fragment="fileSelector(name, multiple)"  th:with="accept=${accept} ?: '*/*', inputText=${inputText} ?: #{pdfPrompt}">
 | 
					<th:block th:fragment="fileSelector(name, multiple)"  th:with="accept=${accept} ?: '*/*', inputText=${inputText} ?: #{pdfPrompt}">
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
        $(document).ready(function() {
 | 
					        $(document).ready(function() {
 | 
				
			||||||
            $('form').submit(function(event) {
 | 
					            $('form').submit(async function(event) {
 | 
				
			||||||
                const boredWaiting = localStorage.getItem('boredWaiting');
 | 
					                const boredWaiting = localStorage.getItem('boredWaiting');
 | 
				
			||||||
                if (boredWaiting === 'enabled') {
 | 
					                if (boredWaiting === 'enabled') {
 | 
				
			||||||
                    $('#show-game-btn').show();
 | 
					                    $('#show-game-btn').show();
 | 
				
			||||||
@ -222,13 +222,14 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
                var url = this.action;
 | 
					                var url = this.action;
 | 
				
			||||||
                console.log(url)
 | 
					                console.log(url)
 | 
				
			||||||
                event.preventDefault(); // Prevent the default form handling behavior
 | 
					                event.preventDefault(); // Prevent the default form handling behavior
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                /* Check if ${multiple} is false */
 | 
					                /* Check if ${multiple} is false */
 | 
				
			||||||
                var multiple = [[${multiple}]] || false;
 | 
					                var multiple = [[${multiple}]] || false;
 | 
				
			||||||
                var override = $('#override').val() || '';
 | 
					                var override = $('#override').val() || '';
 | 
				
			||||||
                console.log("override=" + override)
 | 
					                console.log("override=" + override)
 | 
				
			||||||
                if (override === 'multi' || (!multiple && files.length > 1) && override !== 'single' ) {
 | 
					                if (override === 'multi' || (!multiple && files.length > 1) && override !== 'single' ) {
 | 
				
			||||||
                    console.log("multi parallel download")
 | 
					                    console.log("multi parallel download")
 | 
				
			||||||
                        submitMultiPdfForm(event,url);
 | 
					                    await submitMultiPdfForm(event,url);
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    console.log("start single download")
 | 
					                    console.log("start single download")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -238,10 +239,11 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
                    var formData = new FormData($('form')[0]);
 | 
					                    var formData = new FormData($('form')[0]);
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
                    // Send the request to the server using the fetch() API
 | 
					                    // Send the request to the server using the fetch() API
 | 
				
			||||||
                        fetch(url, {
 | 
					                    const response = await fetch(url, {
 | 
				
			||||||
                        method: 'POST',
 | 
					                        method: 'POST',
 | 
				
			||||||
                        body: formData
 | 
					                        body: formData
 | 
				
			||||||
                        }).then(response => {
 | 
					                    });
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
                        if (!response) {
 | 
					                        if (!response) {
 | 
				
			||||||
                            throw new Error('Received null response for file ' + i);
 | 
					                            throw new Error('Received null response for file ' + i);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
@ -265,7 +267,7 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
                        console.log("contentType=" + contentType)
 | 
					                        console.log("contentType=" + contentType)
 | 
				
			||||||
                        // Check if the response is a PDF or an image
 | 
					                        // Check if the response is a PDF or an image
 | 
				
			||||||
                        if (contentType.includes('pdf') || contentType.includes('image')) {
 | 
					                        if (contentType.includes('pdf') || contentType.includes('image')) {
 | 
				
			||||||
                                response.blob().then(blob => {
 | 
					                            const blob = await response.blob();
 | 
				
			||||||
                            console.log("pdf/image")
 | 
					                            console.log("pdf/image")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            // Perform the appropriate action based on the download option
 | 
					                            // Perform the appropriate action based on the download option
 | 
				
			||||||
@ -288,19 +290,15 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
                                link.download = filename;
 | 
					                                link.download = filename;
 | 
				
			||||||
                                link.click();
 | 
					                                link.click();
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                                });
 | 
					 | 
				
			||||||
                        } else if (contentType.includes('json')) {
 | 
					                        } else if (contentType.includes('json')) {
 | 
				
			||||||
                            // Handle the JSON response
 | 
					                            // Handle the JSON response
 | 
				
			||||||
                                response.json().then(data => {
 | 
					                            const json = await response.json();
 | 
				
			||||||
                            // Format the error message
 | 
					                            // Format the error message
 | 
				
			||||||
                                    const errorMessage = JSON.stringify(data, null, 2);
 | 
					                            const errorMessage = JSON.stringify(json, null, 2);
 | 
				
			||||||
                                    
 | 
					 | 
				
			||||||
                            // Display the error message in an alert
 | 
					                            // Display the error message in an alert
 | 
				
			||||||
                            alert(`An error occurred: ${errorMessage}`);
 | 
					                            alert(`An error occurred: ${errorMessage}`);
 | 
				
			||||||
                                });
 | 
					 | 
				
			||||||
                                
 | 
					 | 
				
			||||||
                        } else {
 | 
					                        } else {
 | 
				
			||||||
                                response.blob().then(blob => {
 | 
					                            const blob = await response.blob()
 | 
				
			||||||
                            console.log("else save 2 zip")
 | 
					                            console.log("else save 2 zip")
 | 
				
			||||||
                            
 | 
					                            
 | 
				
			||||||
                            // For ZIP files or other file types, just download the file
 | 
					                            // For ZIP files or other file types, just download the file
 | 
				
			||||||
@ -308,10 +306,8 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
                            link.href = URL.createObjectURL(blob);
 | 
					                            link.href = URL.createObjectURL(blob);
 | 
				
			||||||
                            link.download = filename;
 | 
					                            link.download = filename;
 | 
				
			||||||
                            link.click();
 | 
					                            link.click();
 | 
				
			||||||
                                });
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    })
 | 
					                    } catch(error) {
 | 
				
			||||||
                        .catch(error => {
 | 
					 | 
				
			||||||
                        console.log("error listener")
 | 
					                        console.log("error listener")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // Extract the error message and stack trace from the response
 | 
					                        // Extract the error message and stack trace from the response
 | 
				
			||||||
@ -326,7 +322,7 @@ document.addEventListener("DOMContentLoaded", function () {
 | 
				
			|||||||
                        // Display the error message to the user
 | 
					                        // Display the error message to the user
 | 
				
			||||||
                        alert(message);
 | 
					                        alert(message);
 | 
				
			||||||
                        
 | 
					                        
 | 
				
			||||||
                        });
 | 
					                    };
 | 
				
			||||||
                        
 | 
					                        
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                $('#submitBtn').text(submitButtonText);
 | 
					                $('#submitBtn').text(submitButtonText);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user