${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);
}
}