Fix docx download: make docx clickable, add forced download via Blob and ObjectURL
This commit is contained in:
parent
2f3b27ac57
commit
fe0a2a0611
@ -232,7 +232,7 @@ class TranscriptionApp {
|
|||||||
const isMd = file.ext === '.md';
|
const isMd = file.ext === '.md';
|
||||||
const isDocx = file.ext === '.docx';
|
const isDocx = file.ext === '.docx';
|
||||||
const icon = isMd ? '📝' : isDocx ? '📄' : '📎';
|
const icon = isMd ? '📝' : isDocx ? '📄' : '📎';
|
||||||
const clickable = isMd ? 'clickable' : '';
|
const clickable = isMd || isDocx ? 'clickable' : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="file-item ${clickable}" data-path="${this.escapeHtml(file.path)}" data-ext="${file.ext}">
|
<div class="file-item ${clickable}" data-path="${this.escapeHtml(file.path)}" data-ext="${file.ext}">
|
||||||
@ -360,11 +360,30 @@ class TranscriptionApp {
|
|||||||
} else if (ext === '.docx') {
|
} else if (ext === '.docx') {
|
||||||
viewer.innerHTML = `
|
viewer.innerHTML = `
|
||||||
<div class="file-preview">
|
<div class="file-preview">
|
||||||
<p>Для просмотра DOCX скачайте файл:</p>
|
<p>Скачивание DOCX...</p>
|
||||||
<a href="/api/files/download?path=${encodeURIComponent(path)}"
|
|
||||||
class="btn-download" download>⬇️ Скачать ${this.escapeHtml(path)}</a>
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
// Принудительное скачивание через 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);
|
||||||
|
viewer.innerHTML = `
|
||||||
|
<div class="file-preview">
|
||||||
|
<p>✅ Файл скачан: ${this.escapeHtml(path)}</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} catch (err) {
|
||||||
|
viewer.innerHTML = `<div class="error">Ошибка скачивания: ${this.escapeHtml(err.message)}</div>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user