diff --git a/backend/static/app.js b/backend/static/app.js index bf6d794..c30f4a0 100644 --- a/backend/static/app.js +++ b/backend/static/app.js @@ -225,6 +225,7 @@ class TranscriptionApp { } container.innerHTML = tree.map(folder => this.renderFolder(folder)).join(''); + this.attachFileItemListeners(); } renderFolder(folder) { @@ -232,10 +233,9 @@ class TranscriptionApp { const isMd = file.ext === '.md'; const isDocx = file.ext === '.docx'; const icon = isMd ? '📝' : isDocx ? '📄' : '📎'; - const clickable = isMd || isDocx ? 'clickable' : ''; return ` -
+
${icon} ${this.escapeHtml(file.name)} ${this.formatBytes(file.size)} @@ -288,13 +288,18 @@ class TranscriptionApp { return; } - // Open file - const fileItem = e.target.closest('.file-item.clickable'); - if (fileItem) { - const path = fileItem.dataset.path; - const ext = fileItem.dataset.ext; + }); + } + + attachFileItemListeners() { + const container = document.getElementById('fileTree'); + container.querySelectorAll('.file-item').forEach(item => { + item.addEventListener('click', (e) => { + e.stopPropagation(); + const path = item.dataset.path; + const ext = item.dataset.ext; this.loadFileContent(path, ext); - } + }); }); } @@ -360,30 +365,22 @@ class TranscriptionApp { } else if (ext === '.docx') { viewer.innerHTML = `
-

Скачивание DOCX...

+

⬇️ Скачивание DOCX...

`; - // Принудительное скачивание через Blob (браузер не блокирует) - try { - const resp = await fetch(`/api/files/download?path=${encodeURIComponent(path)}`); - if (!resp.ok) throw new Error('Download failed'); - const blob = await resp.blob(); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; - a.download = path.split('/').pop(); - document.body.appendChild(a); - a.click(); - a.remove(); - URL.revokeObjectURL(url); + // iframe method — работает без user-gesture restrictions + const iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + iframe.src = `/api/files/download?path=${encodeURIComponent(path)}`; + document.body.appendChild(iframe); + setTimeout(() => { + iframe.remove(); viewer.innerHTML = `
-

✅ Файл скачан: ${this.escapeHtml(path)}

+

✅ Файл скачан

`; - } catch (err) { - viewer.innerHTML = `
Ошибка скачивания: ${this.escapeHtml(err.message)}
`; - } + }, 3000); } }