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.
86 lines
2.9 KiB
JavaScript
86 lines
2.9 KiB
JavaScript
import { StrictMode, useState, useEffect } from 'react'
|
|
import { createRoot } from 'react-dom/client'
|
|
import './index.css'
|
|
import App from './App.jsx'
|
|
import Landing from './Landing.jsx'
|
|
import Legal from './Legal.jsx'
|
|
import { AuthProvider, useAuth } from './contexts/AuthContext'
|
|
import PricingSection from './components/PricingSection'
|
|
import AccountPage from './components/AccountPage'
|
|
import LoginModal from './components/LoginModal'
|
|
|
|
function PageShell({ title, children }) {
|
|
return (
|
|
<div className="min-h-screen bg-background text-white">
|
|
<header className="h-16 border-b border-white/5 flex items-center justify-between px-6">
|
|
<a href="#app" className="font-bold text-lg">OpenShorts</a>
|
|
<a href="#app" className="text-sm text-zinc-400 hover:text-white">← Back to app</a>
|
|
</header>
|
|
<main className="p-8">
|
|
{title && <h1 className="text-3xl font-bold text-center mb-10">{title}</h1>}
|
|
{children}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PricingView() {
|
|
const [showLogin, setShowLogin] = useState(false);
|
|
return (
|
|
<PageShell title="Choose your plan">
|
|
<PricingSection onRequireLogin={() => setShowLogin(true)} />
|
|
{showLogin && <LoginModal onClose={() => setShowLogin(false)} />}
|
|
</PageShell>
|
|
);
|
|
}
|
|
|
|
function AccountView() {
|
|
const { isSignedIn, loading } = useAuth();
|
|
useEffect(() => {
|
|
if (!loading && !isSignedIn) window.location.hash = '#/pricing';
|
|
}, [loading, isSignedIn]);
|
|
return <PageShell><AccountPage /></PageShell>;
|
|
}
|
|
|
|
function Root() {
|
|
const resolveView = () => {
|
|
const hash = window.location.hash || '';
|
|
if (hash.startsWith('#/auth/')) return 'auth'; // AuthContext consumes then redirects
|
|
if (hash.startsWith('#/account')) return 'account';
|
|
if (hash.startsWith('#/pricing')) return 'pricing';
|
|
if (hash === '#legal') return 'legal';
|
|
if (hash === '#app' || localStorage.getItem('openshorts_skip_landing') === '1') return 'app';
|
|
return 'landing';
|
|
};
|
|
|
|
const [view, setView] = useState(resolveView);
|
|
|
|
useEffect(() => {
|
|
const handleHashChange = () => setView(resolveView());
|
|
window.addEventListener('hashchange', handleHashChange);
|
|
return () => window.removeEventListener('hashchange', handleHashChange);
|
|
}, []);
|
|
|
|
const handleLaunchApp = () => {
|
|
localStorage.setItem('openshorts_skip_landing', '1');
|
|
window.location.hash = '#app';
|
|
setView('app');
|
|
};
|
|
|
|
if (view === 'legal') return <Legal />;
|
|
if (view === 'pricing') return <PricingView />;
|
|
if (view === 'account') return <AccountView />;
|
|
if (view === 'auth') {
|
|
return <div className="min-h-screen flex items-center justify-center bg-background text-zinc-400">Signing you in…</div>;
|
|
}
|
|
if (view === 'app') return <App />;
|
|
return <Landing onLaunchApp={handleLaunchApp} />;
|
|
}
|
|
|
|
createRoot(document.getElementById('root')).render(
|
|
<StrictMode>
|
|
<AuthProvider>
|
|
<Root />
|
|
</AuthProvider>
|
|
</StrictMode>,
|
|
)
|