Initial commit
This commit is contained in:
commit
78f8d225ee
21173 changed files with 2907774 additions and 0 deletions
40
app/api/options/lens/route.ts
Normal file
40
app/api/options/lens/route.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// app/api/options/lens/route.ts
|
||||
import { NextResponse } from "next/server";
|
||||
import { directusFetch } from "@/lib/directus";
|
||||
|
||||
/** pick a decent label from whatever fields are readable */
|
||||
function pickLabel(it: any) {
|
||||
const mm = [it?.make, it?.model].filter(Boolean).join(" ").trim();
|
||||
if (mm) return mm;
|
||||
if (it?.name) return String(it.name);
|
||||
const f = it?.focal_length ?? it?.f ?? it?.fl;
|
||||
if (f != null) return `${mm ? mm + " " : ""}${f} mm`.trim();
|
||||
return String(it?.label ?? it?.title ?? it?.id ?? "");
|
||||
}
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const target = searchParams.get("target") || ""; // required
|
||||
const q = (searchParams.get("q") || "").toLowerCase();
|
||||
const limit = Number(searchParams.get("limit") || "500");
|
||||
|
||||
// Fiber / CO2 Galvo / UV -> scan lens ; CO2 Gantry -> focus lens
|
||||
const isGantry = target === "settings_co2gan";
|
||||
const coll = isGantry ? "laser_focus_lens" : "laser_scan_lens";
|
||||
|
||||
// Avoid explicit fields -> prevents 403 on disallowed fields
|
||||
const res = await directusFetch<{ data: any[] }>(`/items/${coll}?limit=${limit}`);
|
||||
let items = res?.data ?? [];
|
||||
|
||||
let rows = items.map((it) => {
|
||||
const label = pickLabel(it);
|
||||
const search = Object.values(it ?? {}).join(" ").toLowerCase();
|
||||
return { id: String(it?.id ?? ""), label, _search: search };
|
||||
}).filter((r) => r.id);
|
||||
|
||||
if (q) rows = rows.filter((r) => r._search.includes(q));
|
||||
rows.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
return NextResponse.json({ data: rows.map(({ _search, ...r }) => r) });
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue