Changes: - Fix datetime serialization with UTC 'Z' suffix for correct timezone display - Add PDF upload support with extension fallback for MIME detection - Fix LOT add/remove by creating new list for SQLAlchemy JSON change detection - Add file message components (FileMessage, ImageLightbox, UploadPreview) - Add multi-file upload support with progress tracking - Link uploaded files to chat messages via message_id - Include file attachments in AI report generation - Update specs for file-storage, realtime-messaging, and ai-report-generation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
87 lines
2.5 KiB
Python
87 lines
2.5 KiB
Python
"""Pydantic schemas for file storage operations"""
|
|
from pydantic import BaseModel, Field, field_validator, field_serializer, ConfigDict
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
|
|
class FileType(str, Enum):
|
|
"""File type enumeration"""
|
|
IMAGE = "image"
|
|
DOCUMENT = "document"
|
|
LOG = "log"
|
|
|
|
|
|
class FileUploadResponse(BaseModel):
|
|
"""Response after successful file upload"""
|
|
file_id: str
|
|
message_id: Optional[str] = None # Associated chat message ID
|
|
filename: str
|
|
file_type: FileType
|
|
file_size: int
|
|
mime_type: str
|
|
download_url: str # Presigned URL
|
|
thumbnail_url: Optional[str] = None # Thumbnail URL for images
|
|
uploaded_at: datetime
|
|
uploader_id: str
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
@field_serializer("uploaded_at")
|
|
def serialize_datetime(self, dt: datetime) -> str:
|
|
"""Serialize datetime with 'Z' suffix to indicate UTC"""
|
|
return dt.isoformat() + "Z"
|
|
|
|
|
|
class FileMetadata(BaseModel):
|
|
"""File metadata response"""
|
|
file_id: str
|
|
message_id: Optional[str] = None # Associated chat message ID
|
|
room_id: str
|
|
filename: str
|
|
file_type: FileType
|
|
mime_type: str
|
|
file_size: int
|
|
minio_bucket: str
|
|
minio_object_path: str
|
|
uploaded_at: datetime
|
|
uploader_id: str
|
|
deleted_at: Optional[datetime] = None
|
|
download_url: Optional[str] = None # Presigned URL (only when requested)
|
|
thumbnail_url: Optional[str] = None # Thumbnail URL for images
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
@field_validator("file_size")
|
|
@classmethod
|
|
def validate_file_size(cls, v):
|
|
"""Validate file size is positive"""
|
|
if v <= 0:
|
|
raise ValueError("File size must be positive")
|
|
return v
|
|
|
|
@field_serializer("uploaded_at", "deleted_at")
|
|
def serialize_datetime(self, dt: Optional[datetime]) -> Optional[str]:
|
|
"""Serialize datetime with 'Z' suffix to indicate UTC"""
|
|
if dt is None:
|
|
return None
|
|
return dt.isoformat() + "Z"
|
|
|
|
|
|
class FileListResponse(BaseModel):
|
|
"""Paginated file list response"""
|
|
files: List[FileMetadata]
|
|
total: int
|
|
limit: int
|
|
offset: int
|
|
has_more: bool
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class FileUploadParams(BaseModel):
|
|
"""Parameters for file upload (optional description)"""
|
|
description: Optional[str] = Field(None, max_length=500)
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|