Files
sofa/app/api/titles/import/route.ts
T
jake 73b07f5ff6 Refactor auth session handling and server actions across app
- Overhaul `lib/auth/server.ts` and `lib/auth/session.ts`; update all API
  routes and server actions to use the revised session pattern
- Refactor server actions (settings, titles, watchlist, setup) for
  consistency with new auth layer
- Extract `SetupForm` into its own client component with `useActionState`,
  animated steps, and copyable env snippets
- Move landing page redirect logic into `app/page.tsx`; slim down
  `LandingPage` component
- Add `proxy.ts` for local dev proxying
- Minor cleanup to `NavBar`, `MobileTabBar`, and `TitleCard`
2026-03-06 17:05:49 -05:00

36 lines
1003 B
TypeScript

import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { z } from "zod";
import { getSession } from "@/lib/auth/session";
import { importTitle } from "@/lib/services/metadata";
const bodySchema = z.object({
tmdbId: z.coerce.number().int().positive(),
type: z.enum(["movie", "tv"]),
});
export async function POST(req: NextRequest) {
const session = await getSession();
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const result = bodySchema.safeParse(await req.json().catch(() => null));
if (!result.success) {
return NextResponse.json(
{ error: "tmdbId (positive integer) and type (movie|tv) are required" },
{ status: 400 },
);
}
try {
const title = await importTitle(result.data.tmdbId, result.data.type);
return NextResponse.json(title);
} catch {
return NextResponse.json(
{ error: "Failed to import title" },
{ status: 502 },
);
}
}