Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import * as settingsService from "@/services/settingsService";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const { searchParams } = new URL(request.url);
|
|
const type = searchParams.get("type") as "flashcards" | "quizzes" || "flashcards";
|
|
const instructions = await settingsService.getLlmInstructions(type);
|
|
return NextResponse.json({ value: instructions });
|
|
}
|
|
|
|
export async function PATCH(request: NextRequest) {
|
|
const { searchParams } = new URL(request.url);
|
|
const type = searchParams.get("type") as "flashcards" | "quizzes" || "flashcards";
|
|
const body = await request.json().catch(() => null);
|
|
|
|
if (!body || typeof body.value !== "string") {
|
|
return NextResponse.json(
|
|
{ error: "value is required" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
if (body.value === "__RESET__") {
|
|
await settingsService.resetLlmInstructions(type);
|
|
const instructions = await settingsService.getLlmInstructions(type);
|
|
return NextResponse.json({ value: instructions });
|
|
}
|
|
|
|
await settingsService.updateLlmInstructions(type, body.value);
|
|
return NextResponse.json({ value: body.value });
|
|
}
|