fix: скачивание больших файлов в админ-панели (нативный download вместо blob)

Кнопка «Скачать» грузила файл через fetch→blob→createObjectURL — весь файл
в память браузера. 14 МБ ок, 1.5 ГБ молча не начинался (лимиты blob, особенно
Firefox). Теперь нативная загрузка через <a download> — браузер стримит на
диск, размер не важен. Эндпоинт /api/admin/file_download принимает токен и
через query-параметр (ссылка не шлёт заголовок). Бамп ADMIN_HTML_VERSION.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-06-02 16:29:35 +10:00
co-authored by Claude Opus 4.8
parent ce9c5b6a9d
commit f17ddc12df
2 changed files with 14 additions and 9 deletions
+6 -7
View File
@@ -282,16 +282,15 @@ async function loadFiles() {
tbl.appendChild(tr);
}
}
async function adminDownload(url, filename) {
// fetch with auth header, then trigger browser download
const r = await fetch(url, {headers: H});
if (!r.ok) { alert('Ошибка скачивания: ' + r.status); return; }
const blob = await r.blob();
function adminDownload(url, filename) {
// Native download: the browser streams straight to disk, so it works for
// multi-GB files. The old fetch→blob approach buffered the whole file in
// browser memory and silently failed on large ones. <a> can't set an auth
// header, so the endpoint also accepts the token via query param.
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.href = url + '&token=' + encodeURIComponent(token);
a.download = filename;
document.body.appendChild(a); a.click(); a.remove();
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
}
// === Invites ===