Refactor storage to rename base_dir to upload_folder.
Renamed `base_dir` to `upload_folder` for better clarity and alignment with its purpose. Adjusted references and settings variable to reflect the updated naming convention. This enhances code readability and consistency.
This commit is contained in:
@@ -37,17 +37,17 @@ class StorageProvider(ABC):
|
||||
class LocalStorageProvider(StorageProvider):
|
||||
"""Local filesystem storage provider."""
|
||||
|
||||
def __init__(self, base_dir: str, files_url_path: str):
|
||||
self.base_dir = Path(base_dir)
|
||||
def __init__(self, upload_folder: str, files_url_path: str):
|
||||
self.upload_folder = Path(upload_folder)
|
||||
self.files_url_path = files_url_path
|
||||
|
||||
# Ensure base directory exists
|
||||
os.makedirs(self.base_dir, exist_ok=True)
|
||||
# Ensure upload directory exists
|
||||
os.makedirs(self.upload_folder, exist_ok=True)
|
||||
|
||||
async def save_file(self, file: UploadFile, destination: str) -> str:
|
||||
"""Save an uploaded file to the local filesystem."""
|
||||
# Ensure destination directory exists
|
||||
dest_path = self.base_dir / destination
|
||||
dest_path = self.upload_folder / destination
|
||||
os.makedirs(dest_path.parent, exist_ok=True)
|
||||
|
||||
# Save the file
|
||||
@@ -86,6 +86,6 @@ class LocalStorageProvider(StorageProvider):
|
||||
def get_storage_provider() -> StorageProvider:
|
||||
"""Dependency for getting the configured storage provider."""
|
||||
return LocalStorageProvider(
|
||||
base_dir=settings.DATA_FILES_DIR,
|
||||
upload_folder=settings.UPLOAD_FOLDER,
|
||||
files_url_path="/files"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user