Refactor local storage service to remove aiofiles dependency
This commit is contained in:
parent
f7f96ad13b
commit
5784940528
1 changed files with 6 additions and 7 deletions
|
|
@ -1,13 +1,12 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import aiofiles
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from .service import StorageService
|
from .service import StorageService
|
||||||
|
|
||||||
|
|
||||||
class LocalStorageService(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):
|
def __init__(self, session_service, settings_service):
|
||||||
"""Initialize the local storage service with session and settings services."""
|
"""Initialize the local storage service with session and settings services."""
|
||||||
|
|
@ -35,8 +34,8 @@ class LocalStorageService(StorageService):
|
||||||
file_path = folder_path / file_name
|
file_path = folder_path / file_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with aiofiles.open(file_path, "wb") as f:
|
with open(file_path, "wb") as f:
|
||||||
await f.write(data)
|
f.write(data)
|
||||||
logger.info(f"File {file_name} saved successfully in flow {flow_id}.")
|
logger.info(f"File {file_name} saved successfully in flow {flow_id}.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error saving file {file_name} in flow {flow_id}: {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}.")
|
logger.warning(f"File {file_name} not found in flow {flow_id}.")
|
||||||
raise FileNotFoundError(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}.")
|
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):
|
async def list_files(self, flow_id: str):
|
||||||
"""
|
"""
|
||||||
|
|
@ -95,4 +94,4 @@ class LocalStorageService(StorageService):
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
"""Perform any cleanup operations when the service is being torn down."""
|
"""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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue