26 lines
926 B
Python
26 lines
926 B
Python
"""add_file — добавить файл в сессию (с проверкой суммарного лимита)."""
|
|
|
|
from . import state
|
|
|
|
|
|
def add_file(sid: str, filename: str, content: bytes) -> bool:
|
|
"""Добавить файл в сессию.
|
|
|
|
Args:
|
|
sid: Идентификатор сессии
|
|
filename: Имя файла
|
|
content: Бинарное содержимое
|
|
|
|
Returns:
|
|
True если добавлено; False если сессии нет или превышен лимит сессии.
|
|
"""
|
|
with state._lock:
|
|
s = state._sessions.get(sid)
|
|
if not s:
|
|
return False
|
|
total = sum(len(c) for _, c in s["files"])
|
|
if total + len(content) > state.MAX_SESSION_BYTES:
|
|
return False # превышен суммарный лимит сессии
|
|
s["files"].append((filename, content))
|
|
return True
|