Spaces:
Running
Running
File size: 6,893 Bytes
3533fb9 d8cd523 3533fb9 0eeeed2 154f032 3533fb9 2893cc2 3533fb9 2893cc2 0eeeed2 3533fb9 4a79015 af296c7 4a79015 af296c7 4a79015 3533fb9 8ad8368 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | 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",
))
|