fix: file path handling for cross-os compatibility (#5342)

* test: add more unit tests

* fix: correct file path splitting to handle OS differences

* [autofix.ci] apply automated fixes

* fix: ruff error

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Ítalo Johnny 2024-12-18 15:51:48 -03:00 committed by GitHub
commit fffc7fb73f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 90 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import base64
from pathlib import Path
from PIL import Image as PILImage
from pydantic import BaseModel
@ -21,7 +22,8 @@ def get_file_paths(files: list[str]):
storage_service = get_storage_service()
file_paths = []
for file in files:
flow_id, file_name = file.split("/")
file_path = Path(file)
flow_id, file_name = str(file_path.parent), file_path.name
file_paths.append(storage_service.build_full_path(flow_id=flow_id, file_name=file_name))
return file_paths
@ -33,8 +35,9 @@ async def get_files(
):
storage_service = get_storage_service()
file_objects: list[str | bytes] = []
for file_path in file_paths:
flow_id, file_name = file_path.split("/")
for file in file_paths:
file_path = Path(file)
flow_id, file_name = str(file_path.parent), file_path.name
file_object = await storage_service.get_file(flow_id=flow_id, file_name=file_name)
if convert_to_base64:
file_base64 = base64.b64encode(file_object).decode("utf-8")