routing fixes
This commit is contained in:
parent
7f75ad7856
commit
a45038241f
4 changed files with 861 additions and 512 deletions
39
app/api/options/material_opacity/route.ts
Normal file
39
app/api/options/material_opacity/route.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// app/api/options/material_opacity/route.ts
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
const BASE = (process.env.DIRECTUS_URL || "").replace(/\/$/, "");
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const ma_at = req.cookies.get("ma_at")?.value;
|
||||
if (!ma_at) return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
|
||||
|
||||
const url = new URL(`${BASE}/items/material_opacity`);
|
||||
url.searchParams.set("fields", "id,opacity");
|
||||
url.searchParams.set("sort", "sort,opacity");
|
||||
|
||||
const res = await fetch(String(url), {
|
||||
headers: { Accept: "application/json", Authorization: `Bearer ${ma_at}` },
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const text = await res.text().catch(() => "");
|
||||
if (!res.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: `Directus ${res.status}: ${text || res.statusText}` },
|
||||
{ status: res.status }
|
||||
);
|
||||
}
|
||||
|
||||
const json = text ? JSON.parse(text) : { data: [] };
|
||||
const data = (json?.data ?? []).map((r: any) => ({
|
||||
id: r.id,
|
||||
label: r.opacity ?? String(r.id),
|
||||
}));
|
||||
|
||||
return NextResponse.json({ data });
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e?.message || "Failed to load opacity options" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue