feat: RCON API transport, full furnidata translation with LibreTranslate fallback, remove organize feature, bump per-page limit to 500

- Add EMULATOR_MODE=api option with HTTP transport mirroring RCON payload
- buildLocalizedFurniDataFiles now falls back to LibreTranslate for customs (incl. pl/ru/ar/ja)
- Remove Organiseer import button from studio and Reorganize Catalog from import page
- Delete organize API route and PUT handler; remove organizeCatalogAll from catalog-repair.ts
- Increase imported-furni list perPage from 50 to 500
This commit is contained in:
openhands committed 2026-08-22 14:28:06 +02:00
1 parent 5668493485
commit 85b5792d40
8 files changed
+146 -768

No files matched your search

-245
View File
@@ -11,12 +11,7 @@ import {
classifyFurni,
getOrCreateCategoryPage,
getOrCreateImportedParentPage,
resetCatalogPageCache,
} from "@/lib/services/furni-import";
import {
classifyCatalogItem,
NO_CATALOG_KINDS,
} from "@/lib/services/item-kind";
export interface MissingCatalogEntry {
classname: string;
@@ -452,246 +447,6 @@ export async function applyCatalogSql(
return { applied, failed };
}
export interface OrganizeCatalogResult {
/** Number of catalog sub-pages created under "Imported Furniture". */
pagesCreated: number;
/** Number of items that got a brand new catalog_items entry. */
catalogAdded: number;
/** Number of existing catalog entries re-homed/re-priced onto their correct page. */
catalogRehomed: number;
}
/**
* Fully automatic one-shot organization of everything that already lives under
* the "Imported Furniture" section of the catalog. For each imported item it:
* 1. ensures the correct target sub-page exists (creating it if missing).
* The target is the item's furniture line (e.g. "weebz", "habbox") when
* known and large enough, otherwise its auto-detected category
* (e.g. "Room & Building", "Rares"),
* 2. re-homes and re-prices any existing catalog entry so it sits on its
* correct sub-page with the canonical auto-detected price.
*
* Only items already present in the Imported section are touched — no new
* items are pulled in from `items_base`. No manual selection required.
*/
export async function organizeCatalogAll(): Promise<OrganizeCatalogResult> {
// 1) Parent page (sub-pages are created on demand below).
const parentPageId = await getOrCreateImportedParentPage();
// Furniture line (brand/series) per classname, sourced from FurnitureData.json
// since `items_base` does not store it. Used to give each line its own page.
const furniData = (await readFurniData()) as Record<
string,
{ furnitype?: Array<{ classname?: string; furniline?: string }> }
>;
const furnilineByClass = new Map<string, string>();
for (const section of ["roomitemtypes", "wallitemtypes"] as const) {
for (const e of furniData[section]?.furnitype ?? []) {
const cn = typeof e.classname === "string" ? e.classname : "";
const fl = typeof e.furniline === "string" ? e.furniline.trim() : "";
if (!cn || !fl) continue;
furnilineByClass.set(cn, fl);
const base = cn.split("*")[0];
if (base && base !== cn) furnilineByClass.set(base, fl);
}
}
const resolveFurniline = (classname: string): string => {
const direct = furnilineByClass.get(classname);
if (direct) return direct;
const base = classname.split("*")[0];
return (base && furnilineByClass.get(base)) || "";
};
// The `caption_save` column is varchar(25). The line prefix `imp_line_`
// takes 9 chars, so the slug may be at most 16 chars to stay within limit.
const slug = (value: string): string =>
value
.toLowerCase()
.replace(/[^a-z0-9]+/g, "_")
.replace(/^_+|_+$/g, "")
.slice(0, 16);
// Minimum number of items a furniture line must have before it gets its own
// dedicated catalog page. Lines below this threshold (one-off customs, etc.)
// collapse onto the category page so we don't create hundreds of tiny pages.
const LINE_PAGE_MIN_ITEMS = 3;
// Ensure a sub-page exists under the imported parent and return its id.
const ensureSubPage = async (
captionSave: string,
caption: string,
): Promise<number> => {
const [existing] = (await db.execute(sql`
SELECT id FROM catalog_pages
WHERE caption_save = ${captionSave} AND parent_id = ${parentPageId}
`)) as unknown as [Array<{ id: number }>, unknown];
if (existing?.[0]?.id) return existing[0].id;
await db.execute(sql`
INSERT INTO catalog_pages (caption_save, caption, page_layout, parent_id, min_rank, order_num, icon_image, enabled, visible, includes, page_headline, page_teaser, page_special, page_text1, page_text2, page_text_details, page_text_teaser)
VALUES (${captionSave}, ${caption}, 'default_3x3', ${parentPageId}, '1', 50, 263, '1', '1', '', '', '', '', '', '', '', '')
`);
const [created] = (await db.execute(sql`
SELECT id FROM catalog_pages
WHERE caption_save = ${captionSave} AND parent_id = ${parentPageId}
`)) as unknown as [Array<{ id: number }>, unknown];
return created?.[0]?.id ?? existing?.[0]?.id ?? 0;
};
// Sub-pages that already exist, so we can count the ones we create.
const [existingPages] = (await db.execute(sql`
SELECT caption_save FROM catalog_pages
WHERE parent_id = ${parentPageId} AND caption_save LIKE 'imp\\_%'
`)) as unknown as [Array<{ caption_save: string }>, unknown];
const existingCaptions = new Set(existingPages.map((r) => r.caption_save));
const createdCaptions = new Set<string>();
let pagesCreated = 0;
// 2) Inventory of items_base + current catalog state.
const [items] = (await db.execute(sql`
SELECT id, item_name, public_name, type, interaction_type
FROM items_base ORDER BY id
`)) as unknown as [
Array<{
id: number;
item_name: string;
public_name: string;
type: string;
interaction_type: string | null;
}>,
unknown,
];
const [catalogRows] = (await db.execute(sql`
SELECT id, item_ids, page_id, cost_credits FROM catalog_items
`)) as unknown as [
Array<{
id: number;
item_ids: string;
page_id: number | string;
cost_credits: number;
}>,
unknown,
];
const catalogPageByItem = new Map<number, number>();
const catalogCreditsByItem = new Map<number, number>();
for (const row of catalogRows) {
const ids = (row.item_ids ?? "")
.split(";")
.map((s) => Number(s.trim()))
.filter(Boolean);
for (const id of ids) {
if (!catalogPageByItem.has(id)) {
catalogPageByItem.set(id, Number(row.page_id));
catalogCreditsByItem.set(id, Number(row.cost_credits));
}
}
}
const [validPages] = (await db.execute(sql`
SELECT id FROM catalog_pages
`)) as unknown as [Array<{ id: number }>, unknown];
const validPageIds = new Set(validPages.map((r) => Number(r.id)));
// Only items already living under the Imported Furniture section are
// reorganized. An item counts as "in import" when its catalog entry sits on
// a sub-page (or the parent) of the imported parent page.
const [importedPages] = (await db.execute(sql`
SELECT id FROM catalog_pages
WHERE parent_id = ${parentPageId} OR id = ${parentPageId}
`)) as unknown as [Array<{ id: number }>, unknown];
const importedPageIds = new Set(importedPages.map((r) => Number(r.id)));
const importedItemIds = new Set<number>();
for (const row of catalogRows) {
if (!importedPageIds.has(Number(row.page_id))) continue;
for (const id of (row.item_ids ?? "")
.split(";")
.map((s) => Number(s.trim()))
.filter(Boolean)) {
importedItemIds.add(id);
}
}
const itemById = new Map(items.map((it) => [Number(it.id), it]));
// Count imported items per furniture line so we only spin up a dedicated
// line page for lines that actually have enough items. Everything else
// falls back to the category page.
const lineCounts = new Map<string, number>();
for (const id of importedItemIds) {
const item = itemById.get(id);
if (!item) continue;
if (NO_CATALOG_KINDS.has(classifyCatalogItem(item))) continue;
const fl = resolveFurniline(item.item_name);
if (fl) lineCounts.set(fl, (lineCounts.get(fl) ?? 0) + 1);
}
const qualifyingLines = new Set<string>();
for (const [line, count] of lineCounts) {
if (count >= LINE_PAGE_MIN_ITEMS) qualifyingLines.add(line);
}
const catalogAdded = 0;
let catalogRehomed = 0;
for (const item of items) {
const kind = classifyCatalogItem(item);
if (NO_CATALOG_KINDS.has(kind)) continue;
const itemId = Number(item.id);
// Only reorganize items already in the Imported Furniture section.
// Never pull new items in from items_base.
if (!importedItemIds.has(itemId)) continue;
// Target page: the item's furniture line (e.g. "weebz", "habbox") when
// it qualifies for its own page, otherwise its auto-detected category.
// The line page is created if it does not exist yet.
let captionSave: string;
let caption: string;
const furniline = resolveFurniline(item.item_name);
if (furniline && slug(furniline) && qualifyingLines.has(furniline)) {
captionSave = `imp_line_${slug(furniline)}`;
caption = furniline;
} else {
const catKey = classifyFurni(item.item_name, item.type);
captionSave = `imp_${catKey}`;
caption = CATEGORY_PAGE[catKey]?.label ?? CATEGORY_PAGE.other.label;
}
if (
!existingCaptions.has(captionSave) &&
!createdCaptions.has(captionSave)
) {
createdCaptions.add(captionSave);
pagesCreated++;
}
const pageId = await ensureSubPage(captionSave, caption);
const price = autoPriceFurni(item.item_name);
// Re-classify onto the correct sub-page and re-apply the auto price if
// either drifted away from the canonical values.
const currentPage = catalogPageByItem.get(itemId);
const currentCredits = catalogCreditsByItem.get(itemId);
const needsMove =
currentPage === undefined ||
!validPageIds.has(currentPage) ||
currentPage !== pageId;
const needsReprice = currentCredits !== price.credits;
if (needsMove || needsReprice) {
await db.execute(sql`
UPDATE catalog_items
SET page_id = ${pageId},
cost_credits = ${price.credits},
cost_points = ${price.points},
points_type = ${price.pointsType}
WHERE item_ids = ${String(itemId)}
`);
catalogRehomed++;
}
}
resetCatalogPageCache();
return { pagesCreated, catalogAdded, catalogRehomed };
}
export interface OrphanedCatalogResult {
removed: number;
cleaned: number;