Rework /get web endpiont

This commit is contained in:
IgorVolochay
2026-01-06 18:15:40 +03:00
parent 6920ff381c
commit 6e7741c946
2 changed files with 42 additions and 4 deletions
+38 -4
View File
@@ -37,25 +37,59 @@ async function handleDownloadPage(fileUuid) {
const data = await response.json(); const data = await response.json();
if (data.error || !data.result || !data.result.data) { 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.className = 'status error';
downloadStatus.style.display = 'block';
return; return;
} }
const fileData = data.result.data; 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 = ` downloadContent.innerHTML = `
<div class="file-info"> <div class="file-info">
<h2>${fileData.file_name}</h2> <h2>${fileData.file_name}</h2>
<p class="file-size">Размер: ${formatBytes(parseInt(fileData.file_size))}</p> <p class="file-size">Размер: ${formatBytes(parseInt(fileData.file_size))}</p>
<a href="${fileData.url}" download="${fileData.file_name}" class="download-button"> <button type="button" id="downloadButton" class="download-button">
Скачать файл Загрузить
</a> </button>
</div> </div>
`; `;
// Attach click handler to the download button
const downloadButton = document.getElementById('downloadButton');
downloadButton.addEventListener('click', handleDownload);
downloadStatus.style.display = 'none'; downloadStatus.style.display = 'none';
} catch (error) { } catch (error) {
downloadStatus.textContent = `Ошибка: ${error.message}`; downloadStatus.textContent = `Ошибка: ${error.message}`;
downloadStatus.className = 'status error'; downloadStatus.className = 'status error';
downloadStatus.style.display = 'block';
} }
} }
+4
View File
@@ -137,6 +137,7 @@ button:disabled {
text-decoration: none; text-decoration: none;
cursor: pointer; cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease; transition: transform 0.2s ease, box-shadow 0.2s ease;
font-family: inherit;
} }
.download-button:hover { .download-button:hover {
@@ -144,3 +145,6 @@ button:disabled {
box-shadow: 0 16px 32px -24px rgba(99, 102, 241, 0.8); box-shadow: 0 16px 32px -24px rgba(99, 102, 241, 0.8);
} }
.download-button:active {
transform: translateY(0);
}