backend / app /core /config.py
Monteeq CI
πŸš€ Deploy from GitHub @ 4d3814559c615ee44b541e9d429783c55d4bbc5c
154f032
Raw History Blame Contribute Delete
6.89 kB
import os
from dotenv import load_dotenv
# Load .env file from the backend directory
env_path = os.path.join(os.path.dirname(__file__), "..", "..", ".env")
load_dotenv(env_path)
SECRET_KEY = os.getenv("SECRET_KEY", "SUPER_SECRET_KEY_CHANGE_ME")
ALGORITHM = os.getenv("ALGORITHM", "HS256")
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "43200"))
GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID", "")
BASE_URL = os.getenv("BASE_URL")
RUST_SERVICE_URL = os.getenv("RUST_SERVICE_URL")
FRONTEND_URL = os.getenv("FRONTEND_URL", "")
STATIC_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "static")
# Comma-separated browser origins for CORS + AntiBot preflight headers.
# Example: https://monteeq.com,https://www.monteeq.com,http://localhost:3000
def _parse_origins(raw: str) -> list[str]:
return [origin.strip().rstrip("/") for origin in (raw or "").split(",") if origin.strip()]
CORS_ALLOWED_ORIGINS = _parse_origins(os.getenv("CORS_ALLOWED_ORIGINS", ""))
_frontend = (FRONTEND_URL or "").strip().rstrip("/")
if _frontend and _frontend not in CORS_ALLOWED_ORIGINS:
CORS_ALLOWED_ORIGINS.append(_frontend)
# Optional regex for additional origin matches (local ports by default).
# Set to empty string to disable.
CORS_ALLOW_ORIGIN_REGEX = os.getenv(
"CORS_ALLOW_ORIGIN_REGEX",
r"http://(localhost|127\.0\.0\.1)(:\d+)?$",
).strip() or None
# Database Configuration
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./sql_app.db")
# Normalize Postgres URLs to use psycopg2 if no driver specified (psycopg3 may not be installed)
if DATABASE_URL and DATABASE_URL.startswith("postgresql://"):
DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+psycopg2://", 1)
elif DATABASE_URL and DATABASE_URL.startswith("postgres://"):
DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+psycopg2://", 1)
# Quota Limits
FLASH_QUOTA_LIMIT = 50
HOME_QUOTA_LIMIT = 20
# Storage Configuration β€” prefer AWS_* from .env; S3_* kept as fallbacks
STORAGE_MODE = os.getenv("STORAGE_MODE", "s3") # 'local' or 's3'
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID") or os.getenv("S3_ACCESS_KEY", "")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY") or os.getenv("S3_SECRET_KEY", "")
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME") or os.getenv("S3_BUCKET_NAME", "monteeq")
AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME") or os.getenv("S3_REGION", "eu-north-1")
_raw_endpoint = os.getenv("S3_ENDPOINT") or ""
S3_ENDPOINT = _raw_endpoint.strip() or None # empty string β†’ native AWS
AWS_S3_USE_ACCELERATE = os.getenv("AWS_S3_USE_ACCELERATE", "false").lower() == "true"
AWS_CLOUDFRONT_DOMAIN = os.getenv("AWS_CLOUDFRONT_DOMAIN", "")
CLOUDFRONT_KEY_PAIR_ID = os.getenv("CLOUDFRONT_KEY_PAIR_ID", "")
# NOTE: For production, consider migrating this to AWS Secrets Manager
# (fetched at startup, cached in memory) instead of an env var.
CLOUDFRONT_PRIVATE_KEY = os.getenv("CLOUDFRONT_PRIVATE_KEY", "")
PAYSTACK_SECRET_KEY = os.getenv("PAYSTACK_SECRET_KEY", "")
# STRIPE_SECRET_KEY = os.getenv("STRIPE_SECRET_KEY", "")
# STRIPE_WEBHOOK_SECRET = os.getenv("STRIPE_WEBHOOK_SECRET", "")
STRIPE_SECRET_KEY = ""
STRIPE_WEBHOOK_SECRET = ""
# Email / SMTP Configuration
SMTP_HOST = os.getenv("SMTP_HOST", "")
SMTP_PORT = int(os.getenv("SMTP_PORT", "587"))
SMTP_USER = os.getenv("SMTP_USER", "")
SMTP_PASS = os.getenv("SMTP_PASS", "")
SMTP_FROM = os.getenv("SMTP_FROM", "")
SMTP_FROM_NAME = os.getenv("SMTP_FROM_NAME", "Monteeq")
# Resend (HTTPS) β€” preferred on hosts that block outbound SMTP (e.g. Hugging Face Spaces).
# Set RESEND_API_KEY in the deployment environment; never commit the key.
# HF deploys only from `main` via GitHub Actions β€” merge this before expecting Space updates.
RESEND_API_KEY = os.getenv("RESEND_API_KEY", "") or os.getenv("RESEND_KEY", "")
# Optional override; defaults to SMTP_FROM (must be a domain verified in Resend).
RESEND_FROM = os.getenv("RESEND_FROM", "") or SMTP_FROM
# Force-disable Zoho SMTP (useful on HF even before Resend is fully verified).
EMAIL_DISABLE_SMTP = os.getenv("EMAIL_DISABLE_SMTP", "").lower() in ("1", "true", "yes")
EMAIL_PROVIDER = os.getenv("EMAIL_PROVIDER", "").strip().lower() # e.g. "resend"
# Redis Configuration (Live Cloud)
REDIS_URL = os.getenv("REDIS_URL")
# ── Monteeq Clips (free asset library) ──────────────────────────────────────
# Private files live under clips/files/ and previews under clips/previews/.
# In local mode the private prefix is stored OUTSIDE the statically served
# directory and is only reachable via signed download-token URLs β€” get_url()
# must never be used for file_key values.
ASSETS_FILE_PREFIX = "clips/files/"
ASSETS_PREVIEW_PREFIX = "clips/previews/"
PRIVATE_STORAGE_DIR = os.getenv(
"PRIVATE_STORAGE_DIR",
os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "private_storage"),
)
# HMAC secret for local-mode download tokens. Falls back to SECRET_KEY so the
# default local setup works with no extra configuration.
ASSETS_DOWNLOAD_SECRET = os.getenv("ASSETS_DOWNLOAD_SECRET", "") or SECRET_KEY
# Short-lived download URL/token lifetime, in seconds.
ASSETS_DOWNLOAD_EXPIRES_SECONDS = int(os.getenv("ASSETS_DOWNLOAD_EXPIRES_SECONDS", "300"))
# Upload limits (bytes). Previews are smaller by default.
ASSETS_MAX_FILE_BYTES = int(os.getenv("ASSETS_MAX_FILE_BYTES", str(500 * 1024 * 1024)))
ASSETS_MAX_PREVIEW_BYTES = int(os.getenv("ASSETS_MAX_PREVIEW_BYTES", str(100 * 1024 * 1024)))
def _parse_ext_list(raw: str) -> set[str]:
return {e.strip().lower() if e.strip().startswith(".") else f".{e.strip().lower()}"
for e in (raw or "").split(",") if e.strip()}
# Allowed downloadable extensions per asset category (lowercase, dotted).
ASSETS_ALLOWED_EXTENSIONS = {
"presets": _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_EXTENSIONS_PRESETS", ".xmp,.lrtemplate,.dng,.zip")),
"luts": _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_EXTENSIONS_LUTS", ".cube,.3dl,.look,.zip")),
"transitions": _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_EXTENSIONS_TRANSITIONS", ".prproj,.mogrt,.mp4,.mov,.zip")),
"overlays": _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_EXTENSIONS_OVERLAYS", ".mp4,.mov,.png,.jpg,.jpeg,.zip")),
"sfx": _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_EXTENSIONS_SFX", ".wav,.mp3,.ogg,.zip")),
"project_files": _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_EXTENSIONS_PROJECT_FILES", ".prproj,.aep,.psd,.drp,.zip")),
}
# Allowed preview extensions (shared across categories).
ASSETS_ALLOWED_PREVIEW_EXTENSIONS = _parse_ext_list(os.getenv(
"ASSETS_ALLOWED_PREVIEW_EXTENSIONS",
".png,.jpg,.jpeg,.gif,.webp,.mp4,.mov,.webm,.wav,.mp3,.ogg",
))