Initial commit

This commit is contained in:
makearmy 2025-09-22 10:37:53 -04:00
commit 78f8d225ee
21173 changed files with 2907774 additions and 0 deletions

View file

@ -0,0 +1,25 @@
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
const BGBYE_URL =
process.env.BGBYE_URL ||
process.env.BG_BYE_URL ||
process.env.BGREMOVER_BASE_URL ||
"http://bgbye:7001";
export async function GET() {
try {
const r = await fetch(`${BGBYE_URL}/methods`, { cache: "no-store" });
const body = await r.text();
return new Response(body, {
status: r.status,
headers: { "content-type": r.headers.get("content-type") || "application/json" },
});
} catch {
return new Response(JSON.stringify({ methods: [] }), {
status: 200,
headers: { "content-type": "application/json" },
});
}
}

43
app/api/bgremove/route.ts Normal file
View file

@ -0,0 +1,43 @@
// /app/api/bgremove/route.ts
import { NextResponse } from "next/server";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
const BGBYE_URL =
process.env.BGBYE_URL ||
process.env.BG_BYE_URL ||
process.env.BGREMOVER_BASE_URL || // <-- support your existing env var
"http://bgbye:7001";
export async function POST(req: Request) {
try {
const inForm = await req.formData();
const method = String(inForm.get("method") || "");
const file = inForm.get("file") as any;
// Loosen the guard: some Node/undici builds return a File-like Blob from a different realm
if (!file || !method) {
return NextResponse.json({ error: "file and method are required" }, { status: 400 });
}
const outForm = new FormData();
const filename = (file as any).name || "upload";
outForm.set("method", method);
outForm.set("file", file, filename);
const res = await fetch(`${BGBYE_URL}/remove_background/`, { method: "POST", body: outForm });
const buf = await res.arrayBuffer();
return new NextResponse(buf, {
status: res.status,
headers: {
"content-type": res.headers.get("content-type") || "application/octet-stream",
"cache-control": "no-store",
},
});
} catch (err: any) {
return NextResponse.json({ error: String(err?.message || err) }, { status: 500 });
}
}