From 5784940528d43dd4984f50a4b92b5f60d4ed25c7 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 16 Feb 2024 15:16:14 -0300 Subject: [PATCH] Refactor local storage service to remove aiofiles dependency --- src/backend/langflow/services/storage/local.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backend/langflow/services/storage/local.py b/src/backend/langflow/services/storage/local.py index fb87a77a0..dcc564441 100644 --- a/src/backend/langflow/services/storage/local.py +++ b/src/backend/langflow/services/storage/local.py @@ -1,13 +1,12 @@ from pathlib import Path -import aiofiles from loguru import logger from .service import StorageService class LocalStorageService(StorageService): - """A service class for handling local storage operations.""" + """A service class for handling local storage operations without aiofiles.""" def __init__(self, session_service, settings_service): """Initialize the local storage service with session and settings services.""" @@ -35,8 +34,8 @@ class LocalStorageService(StorageService): file_path = folder_path / file_name try: - async with aiofiles.open(file_path, "wb") as f: - await f.write(data) + with open(file_path, "wb") as f: + f.write(data) logger.info(f"File {file_name} saved successfully in flow {flow_id}.") except Exception as e: logger.error(f"Error saving file {file_name} in flow {flow_id}: {e}") @@ -56,9 +55,9 @@ class LocalStorageService(StorageService): logger.warning(f"File {file_name} not found in flow {flow_id}.") raise FileNotFoundError(f"File {file_name} not found in flow {flow_id}") - async with aiofiles.open(file_path, "rb") as f: + with open(file_path, "rb") as f: logger.info(f"File {file_name} retrieved successfully from flow {flow_id}.") - return await f.read() + return f.read() async def list_files(self, flow_id: str): """ @@ -95,4 +94,4 @@ class LocalStorageService(StorageService): def teardown(self): """Perform any cleanup operations when the service is being torn down.""" - pass # No specific teardown actions required for local storage at the moment. + pass # No specific teardown actions required for local