feat: implement S3 attachments and presigned uploads
This commit is contained in:
+32
-4
@@ -1,6 +1,6 @@
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
@@ -67,14 +67,20 @@ class Chat(BaseConfig):
|
||||
|
||||
|
||||
class CreateMessage(BaseConfig):
|
||||
text: str = Field(..., min_length=1, max_length=4000)
|
||||
text: str = Field(..., max_length=4000)
|
||||
attachment_ids: List[str] = Field(default_factory=list, max_length=10)
|
||||
|
||||
@field_validator("attachment_ids")
|
||||
@classmethod
|
||||
def validate_attachment_ids(cls, value):
|
||||
if len(value) != len(set(value)):
|
||||
raise ValueError("attachment_ids must be unique")
|
||||
return value
|
||||
|
||||
@field_validator("text")
|
||||
@classmethod
|
||||
def validate_text(cls, value: str) -> str:
|
||||
value = value.strip()
|
||||
if not value:
|
||||
raise ValueError("text must not be blank")
|
||||
return value
|
||||
|
||||
|
||||
@@ -84,6 +90,7 @@ class Message(BaseConfig):
|
||||
sender_id: str
|
||||
text: str
|
||||
created_at: datetime
|
||||
attachment_ids: List[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class Health(BaseConfig):
|
||||
@@ -108,3 +115,24 @@ class ChatPage(BaseConfig):
|
||||
class MessagePage(BaseConfig):
|
||||
items: List[Message]
|
||||
next_cursor: Optional[str] = None
|
||||
|
||||
|
||||
class CreateAttachmentUpload(BaseConfig):
|
||||
filename: str = Field(..., min_length=1, max_length=255)
|
||||
content_type: Literal["image/png", "image/jpeg"]
|
||||
size_bytes: int = Field(..., gt=0, le=10 * 1024 * 1024)
|
||||
sha256: str = Field(..., pattern=r"^[a-fA-F0-9]{64}$")
|
||||
|
||||
@field_validator("filename")
|
||||
@classmethod
|
||||
def validate_filename(cls, value: str) -> str:
|
||||
value = value.strip()
|
||||
|
||||
if (
|
||||
not value
|
||||
or any(c in value for c in ("/", "\\", "\x00"))
|
||||
or any(ord(c) < 32 or ord(c) == 127 for c in value)
|
||||
):
|
||||
raise ValueError("Unsafe filename")
|
||||
|
||||
return value
|
||||
Reference in New Issue
Block a user