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>
5.2 KiB
5.2 KiB
Tasks: Improve File Display and Timezone
Phase 1: Database & Backend Foundation
T-1.1: Database Migration
- Add
message_idcolumn totr_room_filestable (nullable FK totr_messages) - Create Alembic migration script
- Test migration on dev database
T-1.2: File Upload API Update
- Modify
POST /api/rooms/{room_id}/filesto create associated message - Create message with
message_type=image_reforfile_ref - Store message_id in file record
- Return message_id in response
- Update WebSocket broadcast to include message
T-1.3: File Metadata API Update
- Add
message_idto file metadata response - Add
thumbnail_urlfield for image files - Ensure timestamps are formatted in GMT+8
T-1.4: File Deletion Cascade
- Update DELETE endpoint to soft-delete associated message
- Broadcast both
file_deletedandmessage_deletedevents
Phase 2: Frontend File Display
T-2.1: File Message Component
- Create
FileMessage.tsxcomponent - Support
image_reftype with thumbnail - Support
file_reftype with icon - Display caption, sender, timestamp
- Add download button
T-2.2: File Type Icons
- Create file icon mapping (PDF, Excel, text, generic)
- Use appropriate colors (red for PDF, green for Excel, etc.)
- Display file size in human-readable format
T-2.3: Image Lightbox Component
- Create
ImageLightbox.tsxmodal component - Support keyboard navigation (ESC to close)
- Add loading state
- Add download button
- Constrain image to viewport
T-2.4: Integrate File Messages in Chat
- Update
RoomDetail.tsxto renderFileMessagefor image_ref/file_ref - Lazy load images for performance
- Handle click to open lightbox
Phase 3: Upload Experience
T-3.1: Upload Preview Component
- Create
UploadPreview.tsxcomponent - Show thumbnail for images before upload
- Show file info (name, size, icon) for documents
- Add caption/description input field
- Add cancel and send buttons
T-3.2: Update ActionBar Upload Flow
- Modify file selection to show preview instead of immediate upload
- Integrate
UploadPreviewinto input area - Handle upload progress in preview
- Clear preview after successful upload
Phase 4: AI Report Context
T-4.1: Report Data Service Update
- Modify
report_data_service.pyto fetch file context - Join files with their associated messages
- Include surrounding messages (1 before, 1 after)
- Format file entries with context for AI prompt
T-4.2: Update AI Prompt
- Modify prompt to explain file context format
- Include file captions and context in prompt
T-4.3: Update DOCX Assembly
- Add captions below embedded images
- Include file context in attachments section
Phase 5: Timezone Fixes
T-5.1: Audit Timezone Usage
- Review all timestamp displays in frontend
- Identify any remaining GMT+0 usages
- Document locations needing fixes
T-5.2: Apply GMT+8 Consistently
- Update file drawer timestamps to use
formatDateTimeGMT8 - Update report metadata timestamps
- Update any API responses returning timestamps
- Verify backend returns ISO strings (UTC is fine, frontend converts)
Phase 6: Migration & Testing
T-6.1: Data Migration for Existing Files
- Create script to generate messages for orphan files
- Associate existing files with generated messages
- Preserve original upload timestamps
T-6.2: Testing
- Test file upload creates message (API verified)
- Test image thumbnail display in chat (component verified)
- Test lightbox open/close/download (component verified)
- Test non-image file display with icons (component verified)
- Test upload preview flow (component verified)
- Test AI report includes file context (code verified)
- Test all timestamps in GMT+8 (code verified)
- Build verification (frontend builds successfully)
Implementation Summary
Files Modified/Created:
Backend:
app/modules/file_storage/models.py- Addedmessage_idFK columnapp/modules/file_storage/schemas.py- Addedmessage_id,thumbnail_urlfieldsapp/modules/file_storage/services/file_service.py- Updated upload/delete to create/cascade messagesapp/modules/file_storage/router.py- Updated broadcasts with message_idapp/modules/realtime/schemas.py- AddedMessageDeletedBroadcast, updated file broadcastsapp/modules/report_generation/services/report_data_service.py- Added file context fetchingapp/modules/report_generation/services/docx_service.py- GMT+8 timestamps, captionsapp/modules/report_generation/prompts.py- GMT+8 timestamps, file context formatalembic/versions/a1b2c3d4e5f6_add_message_id_to_room_files.py- Migrationscripts/migrate_orphan_files.py- Data migration script
Frontend:
frontend/src/types/index.ts- Updated types with message_id, thumbnail_urlfrontend/src/components/chat/FileMessage.tsx- New component for file messagesfrontend/src/components/chat/ImageLightbox.tsx- New lightbox componentfrontend/src/components/chat/UploadPreview.tsx- New upload preview componentfrontend/src/pages/RoomDetail.tsx- Integrated FileMessage, UploadPreview