Fix docx download: use native <a download> links instead of JS iframe method
This commit is contained in:
parent
0c1d671c8d
commit
37f2b00deb
@ -233,6 +233,17 @@ class TranscriptionApp {
|
||||
const isMd = file.ext === '.md';
|
||||
const isDocx = file.ext === '.docx';
|
||||
const icon = isMd ? '📝' : isDocx ? '📄' : '📎';
|
||||
const downloadUrl = `/api/files/download?path=${encodeURIComponent(file.path)}`;
|
||||
|
||||
if (isDocx) {
|
||||
return `
|
||||
<a href="${downloadUrl}" download="${this.escapeHtml(file.name)}" class="file-item file-download">
|
||||
<span class="file-icon">${icon}</span>
|
||||
<span class="file-name">${this.escapeHtml(file.name)}</span>
|
||||
<span class="file-size">${this.formatBytes(file.size)}</span>
|
||||
</a>
|
||||
`;
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="file-item" data-path="${this.escapeHtml(file.path)}" data-ext="${file.ext}">
|
||||
@ -293,7 +304,7 @@ class TranscriptionApp {
|
||||
|
||||
attachFileItemListeners() {
|
||||
const container = document.getElementById('fileTree');
|
||||
container.querySelectorAll('.file-item').forEach(item => {
|
||||
container.querySelectorAll('.file-item:not(.file-download)').forEach(item => {
|
||||
item.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
const path = item.dataset.path;
|
||||
@ -365,22 +376,9 @@ class TranscriptionApp {
|
||||
} else if (ext === '.docx') {
|
||||
viewer.innerHTML = `
|
||||
<div class="file-preview">
|
||||
<p>⬇️ Скачивание DOCX...</p>
|
||||
<p>⬇️ Нажмите на файл слева для скачивания DOCX</p>
|
||||
</div>
|
||||
`;
|
||||
// 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 = `
|
||||
<div class="file-preview">
|
||||
<p>✅ Файл скачан</p>
|
||||
</div>
|
||||
`;
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -292,11 +292,14 @@ header h1 {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.file-item.clickable {
|
||||
.file-item.clickable, .file-download {
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.file-item.clickable:hover {
|
||||
.file-item.clickable:hover, .file-download:hover {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user