Update config structure and enhance file handling
Renamed API_V1_STR to API_VERSION_STR for consistency. Introduced 'UPLOAD_FOLDER' and ensured its creation, added logging for the data directory path, and implemented allowed image content type validation. Adjusted related references in `main.py`.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
@@ -7,8 +8,13 @@ from typing import Optional, List
|
|||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
PROJECT_NAME: str = "EventSpace"
|
PROJECT_NAME: str = "EventSpace"
|
||||||
VERSION: str = "1.0.0"
|
VERSION: str = "1.0.0"
|
||||||
API_V1_STR: str = "/api/v1"
|
API_VERSION_STR: str = "/api/v1"
|
||||||
DATA_FILES_DIR: str = os.getenv('DATA_FILES_DIR', 'data/')
|
DATA_FILES_DIR: str = os.getenv('DATA_FILES_DIR', '/data')
|
||||||
|
UPLOAD_FOLDER: str = str(Path(DATA_FILES_DIR) / 'uploads')
|
||||||
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
||||||
|
print(
|
||||||
|
f"Data files directory: {DATA_FILES_DIR}"
|
||||||
|
)
|
||||||
|
|
||||||
# Database configuration
|
# Database configuration
|
||||||
POSTGRES_USER: str = "postgres"
|
POSTGRES_USER: str = "postgres"
|
||||||
@@ -30,6 +36,15 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
REFRESH_TOKEN_EXPIRE_DAYS: int = 60
|
REFRESH_TOKEN_EXPIRE_DAYS: int = 60
|
||||||
|
|
||||||
|
# Configure allowed content types for images
|
||||||
|
ALLOWED_IMAGE_TYPES: List[str] = [
|
||||||
|
"image/jpeg",
|
||||||
|
"image/png",
|
||||||
|
"image/gif",
|
||||||
|
"image/svg+xml",
|
||||||
|
"image/webp"
|
||||||
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def database_url(self) -> str:
|
def database_url(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ logger.info(f"Starting app!!!")
|
|||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title=settings.PROJECT_NAME,
|
title=settings.PROJECT_NAME,
|
||||||
version=settings.VERSION,
|
version=settings.VERSION,
|
||||||
openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
openapi_url=f"{settings.API_VERSION_STR}/openapi.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set up CORS middleware
|
# Set up CORS middleware
|
||||||
@@ -46,5 +46,5 @@ async def root():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
app.include_router(api_router, prefix=settings.API_VERSION_STR)
|
||||||
app.mount("/files", StaticFiles(directory=settings.DATA_FILES_DIR), name="static")
|
app.mount("/files", StaticFiles(directory=settings.DATA_FILES_DIR), name="static")
|
||||||
|
|||||||
Reference in New Issue
Block a user