Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>API Response Display</title> | |
| <style> | |
| body { | |
| font-family: Arial, sans-serif; | |
| margin: 20px; | |
| } | |
| .page { | |
| margin-bottom: 40px; | |
| } | |
| .page-number { | |
| font-weight: bold; | |
| margin-bottom: 10px; | |
| } | |
| .iframe-container { | |
| margin-bottom: 20px; | |
| } | |
| .download-link { | |
| display: block; | |
| margin-top: 10px; | |
| } | |
| .loading { | |
| display: none; | |
| font-weight: bold; | |
| color: #333; | |
| } | |
| .error { | |
| display: none; | |
| color: red; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>API Response Display</h1> | |
| <div id="content"></div> | |
| <div id="loading" class="loading">Loading...</div> | |
| <div id="error" class="error"></div> | |
| <input type="file" id="fileInput" style="display: none;"> | |
| <button id="uploadButton">Upload File</button> | |
| <script> | |
| document.getElementById('uploadButton').addEventListener('click', () => { | |
| document.getElementById('fileInput').click(); | |
| }); | |
| document.getElementById('fileInput').addEventListener('change', async () => { | |
| const file = document.getElementById('fileInput').files[0]; | |
| if (!file) return; | |
| const formData = new FormData(); | |
| formData.append('file', file); | |
| document.getElementById('loading').style.display = 'block'; | |
| document.getElementById('error').style.display = 'none'; | |
| try { | |
| const response = await fetch('/uploadfile/', { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| renderPages(data); | |
| } catch (error) { | |
| console.error('Error fetching API response:', error); | |
| document.getElementById('error').textContent = 'An error occurred while fetching the data. Please try again.'; | |
| document.getElementById('error').style.display = 'block'; | |
| } finally { | |
| document.getElementById('loading').style.display = 'none'; | |
| } | |
| }); | |
| function renderPages(data) { | |
| const contentDiv = document.getElementById('content'); | |
| contentDiv.innerHTML = ''; // Clear any existing content | |
| data.forEach(page => { | |
| const pageDiv = document.createElement('div'); | |
| pageDiv.className = 'page'; | |
| const pageNumberDiv = document.createElement('div'); | |
| pageNumberDiv.className = 'page-number'; | |
| pageNumberDiv.textContent = `Page ${page.page_number}`; | |
| const iframeContainer = document.createElement('div'); | |
| iframeContainer.className = 'iframe-container'; | |
| const iframe = document.createElement('iframe'); | |
| iframe.src = page.html.match(/src="([^"]+)"/)[1]; | |
| iframe.width = '100%'; | |
| iframe.height = '600px'; | |
| const downloadLink = document.createElement('div'); | |
| downloadLink.className = 'download-link'; | |
| downloadLink.innerHTML = page.download_link; | |
| iframeContainer.appendChild(iframe); | |
| pageDiv.appendChild(pageNumberDiv); | |
| pageDiv.appendChild(iframeContainer); | |
| pageDiv.appendChild(downloadLink); | |
| contentDiv.appendChild(pageDiv); | |
| }); | |
| } | |
| </script> | |
| </body> | |
| </html> |