From deb39a6e5bec258d7d7536cf99fac06a8eb6c99f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 8 Sep 2025 08:43:53 -0300 Subject: [PATCH] Refactor user file upload and ingestion flow to streamline JWT token handling This commit simplifies the handling of the JWT token in the upload_user_file and run_ingestion functions by removing unnecessary lines and ensuring the token is passed correctly to downstream services. This change enhances code readability and maintains the focus on robust async coding practices and well-documented code. --- src/api/langflow_files.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/langflow_files.py b/src/api/langflow_files.py index 1fa1f9c7..23bd33ec 100644 --- a/src/api/langflow_files.py +++ b/src/api/langflow_files.py @@ -34,9 +34,7 @@ async def upload_user_file( logger.debug("JWT token status", jwt_present=jwt_token is not None) logger.debug("Calling langflow_file_service.upload_user_file") - result = await langflow_file_service.upload_user_file( - file_tuple, jwt_token=jwt_token - ) + result = await langflow_file_service.upload_user_file(file_tuple, jwt_token) logger.debug("Upload successful", result=result) return JSONResponse(result, status_code=201) except Exception as e: @@ -99,15 +97,20 @@ async def run_ingestion( # (search parameters are for retrieval, not document processing) logger.debug("Final tweaks with settings applied", tweaks=tweaks) - # Include user JWT if available jwt_token = getattr(request.state, "jwt_token", None) + if jwt_token: + # Set auth context for downstream services + from auth_context import set_auth_context + + user_id = getattr(request.state, "user_id", None) + set_auth_context(user_id, jwt_token) result = await langflow_file_service.run_ingestion_flow( file_paths=file_paths or [], + jwt_token=jwt_token, session_id=session_id, tweaks=tweaks, - jwt_token=jwt_token, ) return JSONResponse(result) except Exception as e: