Implement reusable upload platform
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
"""Добавление файла в сессию."""
|
||||
|
||||
from . import state
|
||||
|
||||
|
||||
def add_file(sid: str, filename: str, content: bytes) -> bool:
|
||||
"""Добавить файл, если сессия существует и общий лимит не превышен."""
|
||||
|
||||
with state._lock:
|
||||
session = state._sessions.get(sid)
|
||||
if not session:
|
||||
return False
|
||||
total = sum(len(item_content) for _, item_content in session["files"])
|
||||
if total + len(content) > state.MAX_SESSION_BYTES:
|
||||
return False
|
||||
session["files"].append((filename, content))
|
||||
return True
|
||||
Reference in New Issue
Block a user