Adds an optional cloud/paid mode behind a BILLING_ENABLED flag. With the flag off the app is byte-identical to today's self-hosted BYOK build (regression-zero). Backend (cloud/ package, only imported when BILLING_ENABLED): - Auth: magic link (Resend) + Google OAuth (authlib) + JWT sessions - Stripe: hosted Checkout with 3-day card trial, Customer Portal, idempotent order-safe webhooks; 3 plans (Starter/Creator/Pro) resolved by lookup_key - Postgres + SQLAlchemy async; atomic minute metering (reserve/commit/release, plan->topup FIFO, restart-safe) with sweeper - Managed keys: Gemini + Upload-Post server-side for entitled users; paid-only (BYOK core header ignored on hosted); Upload-Post white-label per-user profiles - Metering wired into /api/process (probe->reserve->402, priority queue) and thumbnail image generation (3 min/batch) - yt-dlp residential PROXY_URL support + 720p cap for hosted YouTube downloads Frontend: - AuthContext, LoginModal, PricingSection (3-day trial), AccountPage, UsageMeter, TopUpModal, TrialGate/AdvancedBanner - Paid-only UI: hide BYOK core inputs, trial prompts per tool - Included (Clip Generator, YouTube Studio) vs BYOK (AI Shorts/dubbing: fal.ai + ElevenLabs) clearly separated; ThumbnailStudio + SaaShortsTab managed-aware - Landing: free-self-host vs paid-hosted messaging Verified end-to-end against real Postgres + Stripe test mode.
25 lines
883 B
Python
25 lines
883 B
Python
"""Resolution of server-owned (managed) provider keys for entitled users.
|
|
|
|
Only Gemini and Upload-Post are managed in v1. ElevenLabs and fal stay BYOK.
|
|
The functions here are sync and read from the ``CurrentUser`` snapshot so they
|
|
can be called inline from ``app.py``'s resolve helpers without awaiting.
|
|
"""
|
|
from typing import Optional
|
|
from .config import settings
|
|
|
|
|
|
def has_active_entitlement(user) -> bool:
|
|
"""True if this user may consume managed keys (active plan or top-up credit).
|
|
|
|
The ``entitled`` flag is computed once in Fase 2/3 when the user is loaded
|
|
(active subscription OR remaining top-up minutes).
|
|
"""
|
|
return bool(user is not None and getattr(user, "entitled", False))
|
|
|
|
|
|
def gemini_key() -> Optional[str]:
|
|
return settings.managed_gemini_key or None
|
|
|
|
|
|
def upload_post_key() -> Optional[str]:
|
|
return settings.managed_upload_post_key or None
|