feat(загрузка): свои пределы для архивов — 30 МБ на архив, 100 МБ на диалог, обычные файлы как были; версия 2026-10-08a

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-10-08 20:38:18 +10:00
co-authored by Claude Opus 5.5
parent 5c62b8b509
commit cfa1676d55
6 changed files with 129 additions and 37 deletions
+13 -9
View File
@@ -22,7 +22,7 @@ from pathlib import Path
from fastapi import HTTPException, Request, Response
from starlette.requests import ClientDisconnect
from archive_host import extract_archive_async
from archive_host import extract_archive_async, is_archive_file
TUS_VERSION = "1.0.0"
TUS_EXTENSIONS = "creation,termination"
@@ -97,10 +97,10 @@ def register_tus(app, *, get_user, get_work_dir, is_allowed_file,
raise HTTPException(404, "Upload not found")
return meta
def _pending_bytes(user, tab):
"""Заявленные размеры идущих загрузок человека в диалог. Брошенная лежит до уборки
сутки — её не считаем: в идущую пишут непрерывно, её данные свежие."""
total = 0
def _pending_split(user, tab):
"""(обычные, архивы) — заявленные размеры идущих загрузок человека в диалог. Брошенная
лежит до уборки сутки — её не считаем: в идущую пишут непрерывно, её данные свежие."""
regular = archive = 0
fresh = time.time() - _PENDING_IDLE
for mp in staging.glob("*.json"):
try:
@@ -110,8 +110,11 @@ def register_tus(app, *, get_user, get_work_dir, is_allowed_file,
except (OSError, ValueError):
continue
if m.get("owner") == user and m.get("tab_id") == tab:
total += int(m.get("length") or 0)
return total
if is_archive_file(m.get("filename") or ""):
archive += int(m.get("length") or 0)
else:
regular += int(m.get("length") or 0)
return regular, archive
def _pending_count(user, tab):
"""Сколько загрузок человека в диалог ещё идёт — для предела «файлов за раз»."""
@@ -156,8 +159,9 @@ def register_tus(app, *, get_user, get_work_dir, is_allowed_file,
_name = Path(_m.get("filename", "")).name or "?"
try:
_tab = _safe_tab(_m.get("tab_id"))
check_upload(user, _tab, _name, length, _pending_bytes(user, _tab),
pending_files=_pending_count(user, _tab))
_reg, _arc = _pending_split(user, _tab)
check_upload(user, _tab, _name, length, pending_regular=_reg,
pending_archive=_arc, pending_files=_pending_count(user, _tab))
except HTTPException as refusal:
log_action(user, "tus_reject", "POST", "/api/tus",
f"{_name}: {refusal.detail}", ip, refusal.status_code)