Refactor storage URL retrieval to use get_uploaded_file_url.
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:
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user