echos-ocr/src/app/api/settings/route.ts
Randall Stillwell 7e423a3e50 Build Echo OCR app: full-stack response card scanner
- Next.js 15 + Tailwind v4 + shadcn/ui + TanStack Table
- Prisma + PostgreSQL schema for ResponseCard, ProcessingJob, AppSettings
- Ollama vision integration with structured extraction prompts
- PDF-to-image pipeline with pdf2pic + sharp
- MinIO S3 storage for uploaded files and extracted images
- Chokidar-based folder monitoring for automatic processing
- REST API (9 endpoints) ready for Monday.com integration
- Dashboard with filterable data table, chip filters, bulk actions, CSV export
- Card detail page with editable fields and side-by-side scanned images
- Upload page with drag-and-drop and real-time processing queue
- Settings page for Ollama, folder watch, and Monday.com config
- Dockerfile (multi-stage) + docker-compose for local dev
- Configured for Coolify deployment at echo.stillwell.cloud

Made-with: Cursor
2026-03-10 07:17:45 -05:00

57 lines
1.7 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
export async function GET() {
try {
const settings = await prisma.appSettings.findUnique({
where: { id: "singleton" },
});
if (!settings) {
const created = await prisma.appSettings.create({
data: { id: "singleton" },
});
return NextResponse.json(created);
}
return NextResponse.json(settings);
} catch (error) {
console.error("[settings GET]", error);
return NextResponse.json(
{ error: "Failed to fetch settings" },
{ status: 500 }
);
}
}
export async function PUT(request: NextRequest) {
try {
const body = await request.json().catch(() => ({}));
const data: Record<string, unknown> = {};
if (body.ollamaUrl != null) data.ollamaUrl = String(body.ollamaUrl);
if (body.model != null) data.model = String(body.model);
if (body.watchDir != null) data.watchDir = String(body.watchDir);
if (body.watching != null) data.watching = Boolean(body.watching);
const settings = await prisma.appSettings.upsert({
where: { id: "singleton" },
create: {
id: "singleton",
ollamaUrl: (data.ollamaUrl as string) ?? "http://192.168.68.108:11434",
model: (data.model as string) ?? "llava:7b",
watchDir: (data.watchDir as string) ?? "",
watching: (data.watching as boolean) ?? false,
},
update: data as Parameters<typeof prisma.appSettings.update>[0]["data"],
});
return NextResponse.json(settings);
} catch (error) {
console.error("[settings PUT]", error);
return NextResponse.json(
{ error: "Failed to update settings" },
{ status: 500 }
);
}
}