feat(T05): Dateiablage pro Fahrzeug + File UI with thumbnails and gallery
This commit is contained in:
+29
-28
@@ -1,37 +1,38 @@
|
||||
# Worklog
|
||||
|
||||
## 2026-07-17 - T03: OCR-Erfassung via OpenRouter Vision + OCR UI
|
||||
## T05: Dateiablage pro Fahrzeug + File UI - 2026-07-17
|
||||
|
||||
### Files Created (Backend)
|
||||
- `backend/app/models/ocr_result.py` - OCRResult model (UUID, vehicle_id FK, file_path, status enum, raw_text, structured_data JSONB, confidence_score, error_message, timestamps)
|
||||
- `backend/app/schemas/ocr.py` - OCRUploadResponse, OCRResultResponse, OCRResultListResponse, OCRApplyResponse, OCRStructuredData
|
||||
- `backend/app/utils/openrouter.py` - OpenRouter API client for Qwen2.5-VL vision model (base64 encoding, prompt engineering, JSON parsing, confidence extraction)
|
||||
- `backend/app/services/ocr_service.py` - upload_file, get_result, list_results, apply_to_vehicle, process_ocr (async), MIME/size validation, confidence threshold logic
|
||||
- `backend/app/tasks/ocr_processing.py` - Async background task with independent DB session
|
||||
- `backend/app/tasks/__init__.py` - Tasks package init
|
||||
- `backend/app/routers/ocr.py` - POST /upload, GET /results/:id, GET /results, POST /results/:id/apply
|
||||
- `backend/tests/test_ocr.py` - 33 tests (service unit tests, router integration tests, OpenRouter client tests)
|
||||
### Files Created
|
||||
|
||||
### Files Created (Frontend)
|
||||
- `frontend/lib/ocr.ts` - OCR API client (uploadOCRScan, getOCRResult, listOCRResults, applyOCRToVehicle)
|
||||
- `frontend/components/ocr/OCRUpload.tsx` - Drag-and-drop file upload component
|
||||
- `frontend/components/ocr/OCRResults.tsx` - Results list with pagination and status badges
|
||||
- `frontend/components/ocr/OCRDetail.tsx` - Side-by-side original scan + extracted data with apply button
|
||||
- `frontend/app/[locale]/ocr/page.tsx` - OCR page combining upload, results, and detail
|
||||
- `frontend/tests/ocr.test.tsx` - 18 frontend tests
|
||||
**Backend:**
|
||||
- backend/app/models/file.py - File SQLAlchemy model (UUID, vehicle_id FK, filename, path, mime_type, size, thumbnail_path)
|
||||
- backend/app/schemas/file.py - Pydantic schemas (FileUploadResponse, FileResponse, FileListResponse, FileDeleteResponse)
|
||||
- backend/app/services/file_service.py - File service (upload, get, list, delete, validate_mime_type, validate_file_size)
|
||||
- backend/app/utils/thumbnails.py - Thumbnail generation (200x200) using Pillow for jpg/png/webp
|
||||
- backend/app/routers/files.py - Files router (GET list, POST upload, GET download, DELETE)
|
||||
- backend/tests/test_files.py - 43 tests covering all endpoints, validation, thumbnails, service unit tests
|
||||
|
||||
**Frontend:**
|
||||
- frontend/lib/files.ts - API functions, types, utilities (listFiles, uploadFile, deleteFile, formatFileSize, isImageMime)
|
||||
- frontend/components/files/FileUpload.tsx - Drag-and-drop multi-file upload with validation
|
||||
- frontend/components/files/FileList.tsx - File list with thumbnails, download, delete confirm dialog
|
||||
- frontend/components/files/FileGallery.tsx - Gallery view filtering images only
|
||||
- frontend/components/files/FilePreview.tsx - File preview modal with metadata and download
|
||||
- frontend/tests/files.test.tsx - 25 tests covering all components and utilities
|
||||
|
||||
### Files Modified
|
||||
- `backend/app/config.py` - Added OPENROUTER_API_KEY, OPENROUTER_BASE_URL, OPENROUTER_OCR_MODEL, MAX_FILE_SIZE_MB
|
||||
- `backend/app/main.py` - Registered OCR router under /api/v1/ocr
|
||||
- backend/app/models/vehicle.py - Added files relationship to Vehicle model
|
||||
- backend/app/main.py - Registered files router
|
||||
- backend/requirements.txt - Added Pillow>=10.0.0
|
||||
|
||||
### Test Results
|
||||
- Backend: 33/33 OCR tests passed, 85% coverage (target: 80%)
|
||||
- Backend: 229/229 full suite passed
|
||||
- Frontend: 18/18 OCR tests passed
|
||||
- Backend: 43/43 passed, 82% coverage (file_service 95%, thumbnails 88%, files router 55%)
|
||||
- Frontend: 25/25 passed
|
||||
- TypeScript: tsc --noEmit passes with no errors
|
||||
|
||||
### Key Decisions
|
||||
- Used FastAPI BackgroundTasks for async processing (Redis Queue noted for production)
|
||||
- Confidence threshold: 0.7 (below → manual_review, above → completed)
|
||||
- structured_data JSONB contains: brand, model, vin, first_registration, mileage, power_kw, fuel_type
|
||||
- OpenRouter model: qwen/qwen2.5-vl-72b-instruct (configurable via env)
|
||||
- File validation: image/* MIME types only, max 50 MB
|
||||
### Smoke Test
|
||||
- Backend API endpoints fully functional with real PostgreSQL (upload, list, download, delete)
|
||||
- Thumbnail generation verified for JPEG, PNG, WebP (200x200)
|
||||
- MIME validation enforces jpg/png/webp/pdf/doc/docx only
|
||||
- File size limit enforced at 20MB
|
||||
- Frontend drag-and-drop upload works, delete confirmation dialog works, gallery filters images
|
||||
|
||||
Reference in New Issue
Block a user