import Link from "next/link"; import { redirect } from "next/navigation"; import { getServerSession } from "next-auth"; import { authOptions } from "@/lib/auth"; import { prisma } from "@/lib/db"; import { AccountPrivacyActions } from "@/components/AccountPrivacyActions"; import { PlanBillingActions } from "@/components/PlanBillingActions"; import { DashboardShell } from "@/components/DashboardShell"; import { UpgradeProLink } from "@/components/UpgradeProLink"; import { getUserApiKeyStatus } from "@/lib/api-keys"; import { getApiRateLimitStatus } from "@/lib/api-rate-limit"; import { ApiKeySettings } from "@/components/ApiKeySettings"; import { hasProFeatures, isSelfHostedEdition } from "@/lib/edition"; import { EXTENSION_KIND, getQuotaExtensionUsage } from "@/lib/quota-extensions"; import { getQuotaInfo } from "@/lib/quota"; const PLAN_LABELS = { FREE: "Bedroom Producer", PREMIUM: "Pro", } as const; function InfoRow({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); } export default async function SettingsPage() { const session = await getServerSession(authOptions); if (!session?.user?.email) redirect("/"); const user = await prisma.user.findUnique({ where: { email: session.user.email }, include: { youtubeConnection: true }, }); if (!user) redirect("/"); const quota = await getQuotaInfo(user.id); const selfHosted = isSelfHostedEdition(); const proFeatures = hasProFeatures(user.plan); const extensionUsage = !selfHosted && user.plan === "PREMIUM" ? await getQuotaExtensionUsage(user.id) : null; const apiRateExtensionUsage = proFeatures ? await getQuotaExtensionUsage(user.id, EXTENSION_KIND.API_RATE_LIMIT) : null; const apiKeyStatus = proFeatures ? await getUserApiKeyStatus(user.id) : null; const apiRateLimit = proFeatures ? await getApiRateLimitStatus(user.id) : null; const planLabel = selfHosted ? "Self-hosted" : PLAN_LABELS[user.plan]; const youtube = user.youtubeConnection; const channelUrl = youtube ? `https://www.youtube.com/channel/${youtube.channelId}` : null; return (

Settings

Account information

YouTube

{youtube ? (
) : (

YouTube account not connected.

)} {channelUrl && ( Go to your channel )}

To refresh your YouTube permissions,{" "} sign out and sign in again .

{selfHosted ? "Usage" : "Plan & billing"}

Videos processed

{selfHosted ? ( quota.used ) : ( <> {quota.remaining} {" "} of {quota.limit} videos )}

{!selfHosted && (

{quota.used} used {quota.bonusQuota > 0 ? ` · +${quota.bonusQuota} bonus` : ""}

)}
{!selfHosted && ( <>

{user.plan === "PREMIUM" ? `Monthly quota resets on ${quota.resetsIn}` : `Quota resets in ${quota.resetsIn}`}

)} {selfHosted && (

Self-hosted edition: no video or API quotas.

)}
{!selfHosted && user.plan === "PREMIUM" && user.subscribedAt && ( )} {!selfHosted && user.plan === "PREMIUM" && ( )} {extensionUsage && ( )}
{!selfHosted && user.plan === "FREE" && (

for more videos, 1080p, and lossless audio.

)} {!selfHosted && user.plan === "PREMIUM" && extensionUsage && ( )}
{proFeatures && apiKeyStatus && apiRateLimit && apiRateExtensionUsage && (

API access

)}

Account deletion & data

Request a copy of your data or permanently delete your account and associated uploads.

); }