Harden catalog admin: fix translate/quick-add, RCON sync, and confirm UX.
Local Build and Deploy / deploy (push) Successful in 1m18s

Restore broken Quick Add search, correct Translate saves to items_base and FurnitureData, reparent page deletes, sync RCON on create/toggle/BC mutations, and replace native confirms/prompts with dialogs.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-07-17 21:12:58 +02:00
1 parent de9f837da1
commit b52e25578d
20 files changed
+557 -216

No files matched your search

+8 -11
View File
@@ -1,7 +1,7 @@
import { withAdmin } from "@/lib/api-handler";
import { apiOk } from "@/lib/api-response";
import { PERMS } from "@/lib/permissions";
import { lookupHabboIt } from "@/lib/services/habbo-furnidata-cache";
import { batchLookupByClassnames } from "@/lib/services/habbofurni";
export const GET = withAdmin(
{ permission: PERMS.CATALOG_VIEW },
@@ -13,19 +13,16 @@ export const GET = withAdmin(
.filter(Boolean)
.slice(0, 100);
const found = await batchLookupByClassnames(classnames);
const suggestions: Record<string, { name: string; description: string }> =
{};
await Promise.all(
classnames.map(async (classname) => {
const entry = await lookupHabboIt(classname);
if (!entry) return;
suggestions[classname] = {
name: entry.name ?? "",
description: entry.description ?? "",
};
}),
);
for (const [classname, entry] of found) {
suggestions[classname] = {
name: entry.name ?? "",
description: entry.description ?? "",
};
}
return apiOk({ suggestions });
},
+23 -9
View File
@@ -1,5 +1,3 @@
import { promises as fs } from "node:fs";
import path from "node:path";
import { withAdmin } from "@/lib/api-handler";
import { apiError, apiOk } from "@/lib/api-response";
import { PERMS } from "@/lib/permissions";
@@ -9,6 +7,7 @@ import {
getAncestors,
getTreeFlat,
} from "@/lib/services/catalog-tree";
import { rcon } from "@/lib/services/rcon";
import type { TreeNode } from "@/types/catalog";
type PageRow = {
@@ -262,6 +261,7 @@ export const PATCH = withAdmin(
where: { id: pageId },
data: { [field]: current === "1" ? "0" : "1" },
});
await rcon.updateCatalog();
return apiOk({});
}
const page = await prisma.catalogPages.findUnique({
@@ -274,6 +274,7 @@ export const PATCH = withAdmin(
where: { id: pageId },
data: { [field]: current === "1" ? "0" : "1" },
});
await rcon.updateCatalog();
return apiOk({});
},
);
@@ -304,21 +305,34 @@ export const DELETE = withAdmin(
prisma.catalogPagesBc.delete({ where: { id: pageId } }),
]);
} else {
const children = await prisma.catalogPagesBc.findMany({
where: { parentId: pageId },
select: { id: true },
});
const ids = [pageId, ...children.map((c) => c.id)];
// Deep cascade: collect all descendants
const toDelete: number[] = [pageId];
const queue: number[] = [pageId];
while (queue.length > 0) {
const children = await prisma.catalogPagesBc.findMany({
where: { parentId: { in: queue } },
select: { id: true },
});
queue.length = 0;
for (const child of children) {
toDelete.push(child.id);
queue.push(child.id);
}
}
await prisma.$transaction([
prisma.catalogItemsBc.deleteMany({
where: { pageId: { in: ids } },
where: { pageId: { in: toDelete } },
}),
prisma.catalogPagesBc.deleteMany({
where: { id: { in: toDelete } },
}),
prisma.catalogPagesBc.deleteMany({ where: { id: { in: ids } } }),
]);
}
await rcon.updateCatalog();
return apiOk({});
}
await deletePage(pageId, mode);
await rcon.updateCatalog();
return apiOk({});
},
);
+59
View File
@@ -0,0 +1,59 @@
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,
})),
});
},
);