- Remove .prettierrc (dead config, Biome replaces Prettier) - Rename lighthouserc.json to lighthouserc.cjs with module.exports for ESM compat - Add logger.warn to empty catch blocks in auth, register, site-settings, prisma-cache, redis, security, rate-limit - Unify ActionResult type: action-helper.ts uses 'ok' consistent with safe-action-shared.ts - Add noUnusedLocals + noUnusedParameters to tsconfig + fix 25 pre-existing unused vars - Replace barrel export src/types/index.ts with direct @/types/common imports - Make trustHost conditional (development only) in auth.ts - Add pre-flight URL validation to update-Nitrov3.sh to catch image.library.url misconfigurations - Improve NITRO_IMAGE_LIBRARY_URL content validation in pre-flight & post-compute checks
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
import { withAdmin } from "@/lib/api-handler";
|
|
import { apiOk } from "@/lib/api-response";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
/**
|
|
* Search items_base for Quick Add / catalog tooling.
|
|
* GET ?q=…&limit=30
|
|
*/
|
|
export const GET = withAdmin(
|
|
{ permission: PERMS.CATALOG_VIEW },
|
|
async (request) => {
|
|
const q = (request.nextUrl.searchParams.get("q") || "").trim();
|
|
const limit = Math.min(
|
|
Math.max(
|
|
Number.parseInt(
|
|
request.nextUrl.searchParams.get("limit") || "30",
|
|
10,
|
|
) || 30,
|
|
1,
|
|
),
|
|
50,
|
|
);
|
|
|
|
if (q.length < 2) {
|
|
return apiOk({ results: [] });
|
|
}
|
|
|
|
const idExact = Number.parseInt(q, 10);
|
|
const rows = await prisma.itemsBase.findMany({
|
|
where: {
|
|
OR: [
|
|
{ itemName: { contains: q } },
|
|
{ publicName: { contains: q } },
|
|
...(Number.isFinite(idExact) && String(idExact) === q
|
|
? [{ id: idExact }]
|
|
: []),
|
|
],
|
|
},
|
|
select: {
|
|
id: true,
|
|
itemName: true,
|
|
publicName: true,
|
|
type: true,
|
|
spriteId: true,
|
|
},
|
|
take: limit,
|
|
orderBy: { id: "asc" },
|
|
});
|
|
|
|
return apiOk({
|
|
results: rows.map((r) => ({
|
|
id: r.id,
|
|
itemName: r.itemName ?? "",
|
|
publicName: r.publicName ?? "",
|
|
type: r.type ?? "s",
|
|
spriteId: r.spriteId ?? 0,
|
|
})),
|
|
});
|
|
},
|
|
);
|