diff --git a/frontend/script.js b/frontend/script.js index 96d2da5..6ebaca0 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -37,25 +37,59 @@ async function handleDownloadPage(fileUuid) { const data = await response.json(); if (data.error || !data.result || !data.result.data) { - downloadStatus.textContent = data.result?.comment || 'Ошибка при получении файла'; + downloadStatus.textContent = data.result?.comment || data.result || 'Ошибка при получении файла'; downloadStatus.className = 'status error'; + downloadStatus.style.display = 'block'; return; } const fileData = data.result.data; + + // Create download button handler + const handleDownload = async () => { + try { + // For presigned URLs, we fetch the file and create a blob URL + const response = await fetch(fileData.url); + if (!response.ok) { + throw new Error('Ошибка при загрузке файла'); + } + const blob = await response.blob(); + const blobUrl = window.URL.createObjectURL(blob); + + const link = document.createElement('a'); + link.href = blobUrl; + link.download = fileData.file_name; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // Clean up the blob URL + window.URL.revokeObjectURL(blobUrl); + } catch (error) { + // Fallback: try direct navigation + window.location.href = fileData.url; + } + }; + downloadContent.innerHTML = `

${fileData.file_name}

Размер: ${formatBytes(parseInt(fileData.file_size))}

- - Скачать файл - +
`; + + // Attach click handler to the download button + const downloadButton = document.getElementById('downloadButton'); + downloadButton.addEventListener('click', handleDownload); + downloadStatus.style.display = 'none'; } catch (error) { downloadStatus.textContent = `Ошибка: ${error.message}`; downloadStatus.className = 'status error'; + downloadStatus.style.display = 'block'; } } diff --git a/frontend/style.css b/frontend/style.css index 31371fd..09486a7 100644 --- a/frontend/style.css +++ b/frontend/style.css @@ -137,6 +137,7 @@ button:disabled { text-decoration: none; cursor: pointer; transition: transform 0.2s ease, box-shadow 0.2s ease; + font-family: inherit; } .download-button:hover { @@ -144,3 +145,6 @@ button:disabled { box-shadow: 0 16px 32px -24px rgba(99, 102, 241, 0.8); } +.download-button:active { + transform: translateY(0); +}