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:
@@ -1008,7 +1008,13 @@ async def admin_download_file_endpoint(request: Request):
|
||||
Path components passed as query params to avoid URL-escaping pain
|
||||
with names like `!Реестр СМ..xlsm` and tab_ids containing slashes.
|
||||
"""
|
||||
_require_admin(request)
|
||||
# Native browser download of large files can't send an Authorization header,
|
||||
# so accept the admin token via query param as a fallback to the header.
|
||||
from auth import get_token_role
|
||||
_tok = (request.headers.get("authorization", "").removeprefix("Bearer ").strip()
|
||||
or request.query_params.get("token", "").strip())
|
||||
if not verify_token(_tok) or get_token_role(_tok) != "admin":
|
||||
raise HTTPException(403, "Admin only")
|
||||
target_user = request.query_params.get("username", "").strip()
|
||||
tab_id = request.query_params.get("tab_id", "").strip()
|
||||
filename = request.query_params.get("filename", "").strip()
|
||||
@@ -1030,7 +1036,7 @@ async def admin_download_file_endpoint(request: Request):
|
||||
return FileResponse(fpath, filename=safe_name)
|
||||
|
||||
|
||||
ADMIN_HTML_VERSION = "20260506g"
|
||||
ADMIN_HTML_VERSION = "20260602a"
|
||||
|
||||
|
||||
@app.get("/admin", response_class=HTMLResponse)
|
||||
|
||||
Reference in New Issue
Block a user