feat: Improve file display, timezone handling, and LOT management
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>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""Pydantic schemas for file storage operations"""
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from pydantic import BaseModel, Field, field_validator, field_serializer, ConfigDict
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
@@ -15,21 +15,28 @@ class FileType(str, Enum):
|
||||
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
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
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
|
||||
@@ -41,9 +48,9 @@ class FileMetadata(BaseModel):
|
||||
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
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@field_validator("file_size")
|
||||
@classmethod
|
||||
@@ -53,6 +60,13 @@ class FileMetadata(BaseModel):
|
||||
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"""
|
||||
@@ -62,13 +76,11 @@ class FileListResponse(BaseModel):
|
||||
offset: int
|
||||
has_more: bool
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class FileUploadParams(BaseModel):
|
||||
"""Parameters for file upload (optional description)"""
|
||||
description: Optional[str] = Field(None, max_length=500)
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
Reference in New Issue
Block a user