52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import secrets
|
|
from typing import List
|
|
from pathlib import Path
|
|
|
|
from pydantic import AnyHttpUrl, field_validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
# Project base directory
|
|
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
|
|
|
# Database directories
|
|
DB_DIR = Path("/app") / "storage" / "db"
|
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Media directories
|
|
MEDIA_DIR = BASE_DIR / "storage" / "media"
|
|
AUDIO_DIR = MEDIA_DIR / "audio"
|
|
IMAGES_DIR = MEDIA_DIR / "images"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "Music Streaming API"
|
|
|
|
# SECURITY
|
|
SECRET_KEY: str = secrets.token_urlsafe(32)
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8 # 8 days
|
|
|
|
# Database
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
# Storage Paths
|
|
AUDIO_DIR: Path = AUDIO_DIR
|
|
IMAGES_DIR: Path = IMAGES_DIR
|
|
|
|
# CORS
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@field_validator("BACKEND_CORS_ORIGINS", mode="before")
|
|
def assemble_cors_origins(cls, v: str | List[str]) -> List[str] | str:
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
elif isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings() |