Upload a file and ingest into the RAG pipeline. Delegates business logic to file_service. Validates file extension against SUPPORTED_EXTENSIONS.
(file: UploadFile = File(...), db: Session = Depends(get_db))
| 114 | |
| 115 | @app.post("/api/upload", response_model=FileUploadResponse) |
| 116 | def upload_file(file: UploadFile = File(...), db: Session = Depends(get_db)) -> FileUploadResponse: |
| 117 | """ |
| 118 | Upload a file and ingest into the RAG pipeline. Delegates business logic to file_service. |
| 119 | Validates file extension against SUPPORTED_EXTENSIONS. |
| 120 | """ |
| 121 | ext = os.path.splitext(file.filename)[-1].lower() |
| 122 | if ext not in SUPPORTED_EXTENSIONS: |
| 123 | raise HTTPException(status_code=422, detail=f"Unsupported file type: {ext}") |
| 124 | db_file = upload_file_service(file=file, db=db) |
| 125 | # Ingest into RAG pipeline (kept here to avoid circular dependency) |
| 126 | try: |
| 127 | rag_pipeline.ingest(db_file.filepath, metadata={"file_id": db_file.id, "filename": db_file.filename}) |
| 128 | except Exception as e: |
| 129 | db.delete(db_file) |
| 130 | db.commit() |
| 131 | os.remove(db_file.filepath) |
| 132 | raise HTTPException(status_code=500, detail=f"RAG ingestion failed: {str(e)}") |
| 133 | return FileUploadResponse(id=db_file.id, filename=db_file.filename) |
| 134 | |
| 135 | |
| 136 | from app.services.file_service import list_files as list_files_service |
nothing calls this directly
no test coverage detected