Initial commit: PodcastYes — AI podcast platform
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { requireAuth } from "@/lib/auth/guards";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { PageHeader } from "@/components/app/page-header";
|
||||
import { SeriesDetailClient } from "@/components/app/series-detail-client";
|
||||
import { EpisodeStatusBadge } from "@/components/app/episode-status-badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
|
||||
export default async function SeriesDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const session = await requireAuth();
|
||||
|
||||
const series = await prisma.series.findUnique({
|
||||
where: { id },
|
||||
include: { episodes: { orderBy: { createdAt: "desc" } } },
|
||||
});
|
||||
if (!series) notFound();
|
||||
if (series.userId !== session.user.id && session.user.role !== "admin") notFound();
|
||||
|
||||
const planned = (series.plan as unknown as { title: string; topic: string; summary: string }[]) ?? [];
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button asChild variant="ghost" size="sm" className="mb-2">
|
||||
<Link href="/series">
|
||||
<ArrowLeft className="h-4 w-4" /> Back to series
|
||||
</Link>
|
||||
</Button>
|
||||
<PageHeader title={series.title} description={series.description ?? undefined} />
|
||||
|
||||
<h2 className="mb-3 text-sm font-semibold text-muted-foreground">Planned episodes</h2>
|
||||
<SeriesDetailClient seriesId={series.id} episodes={planned} />
|
||||
|
||||
{series.episodes.length > 0 && (
|
||||
<div className="mt-8">
|
||||
<h2 className="mb-3 text-sm font-semibold text-muted-foreground">Generated</h2>
|
||||
<div className="space-y-2">
|
||||
{series.episodes.map((ep) => (
|
||||
<Link key={ep.id} href={`/episodes/${ep.id}`}>
|
||||
<Card className="transition-shadow hover:shadow-md">
|
||||
<CardContent className="flex items-center justify-between py-3">
|
||||
<span className="truncate font-medium">{ep.title}</span>
|
||||
<EpisodeStatusBadge status={ep.status} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import { getServerSession } from "@/lib/auth/guards";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { subjectHasFeature } from "@/lib/billing/subscription";
|
||||
import { enforceLimit, LimitExceededError } from "@/lib/usage/limits";
|
||||
import { enqueueEpisodeGeneration } from "@/lib/queue/pgboss";
|
||||
import { FORMAT_SPEAKERS } from "@/lib/episodes/options";
|
||||
import { DEFAULT_VOICE_IDS, VOICE_CATALOG } from "@/lib/ai/voices";
|
||||
|
||||
const createSchema = z.object({
|
||||
theme: z.string().min(5).max(500),
|
||||
count: z.number().int().min(2).max(12),
|
||||
tone: z.string().min(1),
|
||||
audience: z.string().max(200).optional(),
|
||||
language: z.string().min(2).max(5),
|
||||
});
|
||||
|
||||
export async function createSeriesAction(
|
||||
input: z.infer<typeof createSchema>
|
||||
): Promise<{ ok: boolean; error?: string; seriesId?: string }> {
|
||||
const session = await getServerSession();
|
||||
if (!session) return { ok: false, error: "You must be signed in." };
|
||||
if (!(await subjectHasFeature(session.user.id, "series_generator", session.session.activeOrganizationId))) {
|
||||
return { ok: false, error: "The series generator requires the Pro plan." };
|
||||
}
|
||||
const parsed = createSchema.safeParse(input);
|
||||
if (!parsed.success) return { ok: false, error: parsed.error.issues[0]?.message ?? "Invalid input." };
|
||||
|
||||
const { planSeason } = await import("@/lib/ai/series");
|
||||
const { plan } = await planSeason(parsed.data);
|
||||
|
||||
const series = await prisma.series.create({
|
||||
data: {
|
||||
userId: session.user.id,
|
||||
organizationId: session.session.activeOrganizationId ?? undefined,
|
||||
title: plan.title,
|
||||
description: plan.description,
|
||||
plannedCount: plan.episodes.length,
|
||||
plan: plan.episodes as unknown as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
revalidatePath("/series");
|
||||
return { ok: true, seriesId: series.id };
|
||||
}
|
||||
|
||||
export async function generateFromSeriesAction(
|
||||
seriesId: string,
|
||||
index: number
|
||||
): Promise<{ ok: boolean; error?: string; episodeId?: string }> {
|
||||
const session = await getServerSession();
|
||||
if (!session) return { ok: false, error: "You must be signed in." };
|
||||
|
||||
const series = await prisma.series.findUnique({ where: { id: seriesId } });
|
||||
if (!series || series.userId !== session.user.id) return { ok: false, error: "Not allowed." };
|
||||
|
||||
const episodes = (series.plan as unknown as { title: string; topic: string; summary: string }[]) ?? [];
|
||||
const item = episodes[index];
|
||||
if (!item) return { ok: false, error: "Episode not found in plan." };
|
||||
|
||||
try {
|
||||
await enforceLimit(session.user.id, "script", session.session.activeOrganizationId);
|
||||
await enforceLimit(session.user.id, "audio", session.session.activeOrganizationId);
|
||||
} catch (err) {
|
||||
if (err instanceof LimitExceededError) {
|
||||
return { ok: false, error: `Monthly ${err.check.metric} limit reached.` };
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
const speakers = FORMAT_SPEAKERS.SOLO.map((s, i) => ({
|
||||
speakerKey: s.speakerKey,
|
||||
displayName: s.defaultName,
|
||||
elevenVoiceId: DEFAULT_VOICE_IDS[s.speakerKey] ?? VOICE_CATALOG[i % VOICE_CATALOG.length].id,
|
||||
}));
|
||||
|
||||
const episode = await prisma.episode.create({
|
||||
data: {
|
||||
userId: session.user.id,
|
||||
organizationId: series.organizationId ?? undefined,
|
||||
seriesId: series.id,
|
||||
title: item.title,
|
||||
topic: item.topic,
|
||||
tone: "Conversational",
|
||||
format: "SOLO",
|
||||
language: "en",
|
||||
targetLengthMin: 10,
|
||||
status: "QUEUED",
|
||||
stage: "Queued for generation",
|
||||
speakers: { create: speakers },
|
||||
jobs: { create: { type: "full", status: "queued" } },
|
||||
},
|
||||
});
|
||||
await enqueueEpisodeGeneration({ episodeId: episode.id, type: "full" });
|
||||
|
||||
revalidatePath(`/series/${seriesId}`);
|
||||
return { ok: true, episodeId: episode.id };
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { ListMusic } from "lucide-react";
|
||||
import { requireAuth } from "@/lib/auth/guards";
|
||||
import { subjectHasFeature } from "@/lib/billing/subscription";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { PageHeader } from "@/components/app/page-header";
|
||||
import { UpgradeGate } from "@/components/app/upgrade-gate";
|
||||
import { SeriesCreateForm } from "@/components/app/series-create-form";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
|
||||
export const metadata: Metadata = { title: "Series" };
|
||||
|
||||
export default async function SeriesPage() {
|
||||
const session = await requireAuth();
|
||||
const allowed = await subjectHasFeature(
|
||||
session.user.id,
|
||||
"series_generator",
|
||||
session.session.activeOrganizationId
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="Series generator" description="Plan a whole season at once." />
|
||||
<UpgradeGate
|
||||
title="Series generator is a Pro feature"
|
||||
description="Upgrade to Pro to plan entire seasons and batch-generate episodes."
|
||||
requiredPlan="Pro"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const series = await prisma.series.findMany({
|
||||
where: { userId: session.user.id },
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: { _count: { select: { episodes: true } } },
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title="Series generator"
|
||||
description="Plan a cohesive season, then generate each episode."
|
||||
/>
|
||||
|
||||
<SeriesCreateForm />
|
||||
|
||||
{series.length > 0 && (
|
||||
<div className="mt-8 space-y-3">
|
||||
<h2 className="text-sm font-semibold text-muted-foreground">Your seasons</h2>
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{series.map((s) => (
|
||||
<Link key={s.id} href={`/series/${s.id}`}>
|
||||
<Card className="transition-shadow hover:shadow-md">
|
||||
<CardContent className="flex items-center gap-3 py-4">
|
||||
<span className="flex h-11 w-11 items-center justify-center rounded-xl bg-brand/10 text-brand">
|
||||
<ListMusic className="h-5 w-5" />
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<p className="truncate font-medium">{s.title}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{s.plannedCount} planned · {s._count.episodes} generated
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user