mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
- 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`
36 lines
1015 B
TypeScript
36 lines
1015 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getSession } from "@/lib/auth/session";
|
|
import { triggerJob } from "@/lib/cron";
|
|
|
|
export async function POST(request: Request) {
|
|
const session = await getSession();
|
|
if (!session) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
if (session.user.role !== "admin") {
|
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
}
|
|
|
|
let body: unknown;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 });
|
|
}
|
|
const jobName = (body as { jobName?: unknown })?.jobName;
|
|
|
|
if (!jobName || typeof jobName !== "string") {
|
|
return NextResponse.json(
|
|
{ error: "Missing jobName in request body" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const triggered = await triggerJob(jobName);
|
|
if (!triggered) {
|
|
return NextResponse.json({ error: "Job not found" }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({ ok: true, jobName });
|
|
}
|