forked from mtusi2026/mtusi2026lab4
Добавить приватное хранилище вложений и отдачу файла через API.
Байты лежат в SeaweedFS, метаданные в Postgres. Другая реплика скачивает тот же объект, потому что локальный диск API не является источником файла.
This commit is contained in:
+32
-3
@@ -80,16 +80,45 @@ def validate_idempotency_key(value: Optional[str]) -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def validate_message_text(value: Any) -> Optional[str]:
|
||||
def validate_message_text(value: Any, *, allow_blank: bool = False) -> Optional[str]:
|
||||
if not isinstance(value, str):
|
||||
return "invalid text"
|
||||
if not value.strip():
|
||||
return "text must not be blank"
|
||||
if len(value) > 4000:
|
||||
return "text too long"
|
||||
if not allow_blank and not value.strip():
|
||||
return "text must not be blank"
|
||||
return None
|
||||
|
||||
|
||||
def validate_filename(value: Optional[str]) -> Optional[str]:
|
||||
if not isinstance(value, str) or not value.strip() or len(value) > 255:
|
||||
return "invalid filename"
|
||||
for char in value:
|
||||
code = ord(char)
|
||||
if code < 32 or code == 127 or char in "/\\":
|
||||
return "invalid filename"
|
||||
return None
|
||||
|
||||
|
||||
def parse_attachment_ids(value: Any) -> Tuple[Optional[list], Optional[str]]:
|
||||
if value is None:
|
||||
return [], None
|
||||
if not isinstance(value, list):
|
||||
return None, "invalid attachment_ids"
|
||||
if len(value) > 10:
|
||||
return None, "too many attachments"
|
||||
seen = set()
|
||||
ids = []
|
||||
for item in value:
|
||||
if validate_uuid(item):
|
||||
return None, "invalid attachment id"
|
||||
if item in seen:
|
||||
return None, "duplicate attachment_ids"
|
||||
seen.add(item)
|
||||
ids.append(item)
|
||||
return ids, None
|
||||
|
||||
|
||||
def validate_limit(value: Optional[str], default: int = 50) -> Tuple[Optional[int], Optional[str]]:
|
||||
if value is None:
|
||||
return default, None
|
||||
|
||||
Reference in New Issue
Block a user