Refactor storage URL retrieval to use get_uploaded_file_url.
Some checks failed
Build and Push Docker Images / build-frontend (push) Blocked by required conditions
Build and Push Docker Images / changes (push) Successful in 3s
Build and Push Docker Images / build-backend (push) Has been cancelled

Replaced calls to get_file_url with get_uploaded_file_url where appropriate. Added the get_uploaded_file_url method to the StorageProvider class and its implementations for more specific URL generation. Updated corresponding tests and API routes to reflect this change.
This commit is contained in:
2025-03-14 00:05:07 +01:00
parent 8c1e6b7ebe
commit 0cf5498762
3 changed files with 13 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ from app.core.config import settings
class StorageProvider(ABC):
"""Base abstract class for storage providers."""
upload_folder: Path
@abstractmethod
async def save_file(self, file: UploadFile, destination: str) -> str:
"""Save a file to storage and return the relative path."""
@@ -28,6 +29,11 @@ class StorageProvider(ABC):
"""
pass
@abstractmethod
def get_uploaded_file_url(self, file_path: str) -> str:
"""Get the URL for accessing a file."""
pass
@abstractmethod
def get_file_url(self, file_path: str) -> str:
"""Get the URL for accessing a file."""
@@ -74,10 +80,14 @@ class LocalStorageProvider(StorageProvider):
upload_url = f"{settings.API_VERSION_STR}/uploads/{token}"
# The file URL is where the file will be accessible after upload
file_url = f"{self.files_url_path}/{file_path}"
file_url = f"{self.upload_folder}/{file_path}"
return upload_url, file_url
def get_uploaded_file_url(self, file_path: str) -> str:
"""Get the URL for accessing a file."""
return f"{self.upload_folder}/{file_path}"
def get_file_url(self, file_path: str) -> str:
"""Get the URL for accessing a file."""
return f"{self.files_url_path}/{file_path}"