fix: harden furni import pipeline for production
CI / check (push) Successful in 26s
CI / release (push) Skipped
CI / deploy (push) Successful in 57s

- importSingleFurni: actually update an existing item instead of failing on a primary key INSERT collision; refuse to reassign a spriteId owned by a different classname
- reconcileFurniDataWithItemsBase: also sync each entry's offerid to the DB sprite id, not just the id
- Move the full-table interaction_modes_count verification out of the per-item import hot path and run it once per batch/single import
- clone-import: apply the auto-detected interaction_type (was hardcoded 'default'), set FurnitureData offerid and catalog_items.offer_id to the new local sprite id (was the source hotel's id / -1)
- clone batch route: run the same post-import reconcile/verify/ownership/RCON consolidation as the furni batch route
- upload-import: set offer_id to the allocated id in both the direct insert and the generated SQL migration (was -1)
- generateCatalogSql: use the classname as catalog_name and the item id as offer_id so rows match the app-managed import convention
- stats + missing-nitro endpoints: match catalog membership via item_ids instead of the catalog_name join, so translated display names no longer break counts
- deleteImportedItem/rollback: delete catalog rows by the canonical item_ids link only
- classifyFurni: wall items always classify as 'walls' before prefix rules (rare_/val_/xmas_) can misfile them
This commit is contained in:
openhands committed 2026-08-20 11:48:51 +02:00
1 parent 2b9a015afb
commit 6021a91ef7
9 files changed
+162 -66

No files matched your search

@@ -10,8 +10,16 @@ import { getSource } from "@/lib/services/clone-sources";
import { import {
appendFurniEntriesBatch, appendFurniEntriesBatch,
appendFurniEntry, appendFurniEntry,
reconcileFurniDataWithItemsBase,
} from "@/lib/services/furni-data"; } from "@/lib/services/furni-data";
import {
ensureFurniOwnership,
reconcileImportedOfferIds,
syncAssetsToGamedataBundle,
verifyAndFixInteractionModesCount,
} from "@/lib/services/furni-import";
import { runSseBatch } from "@/lib/services/import/core/sse-batch"; import { runSseBatch } from "@/lib/services/import/core/sse-batch";
import { rcon } from "@/lib/services/rcon";
interface BatchItem { interface BatchItem {
classname: string; classname: string;
@@ -126,6 +134,22 @@ export const POST = withAdmin(
`FurnitureData batch write failed: ${(err as Error).message}`, `FurnitureData batch write failed: ${(err as Error).message}`,
); );
} }
// Post-import consolidation, mirroring the furni batch route:
// keep offer_id / FurnitureData offerid in sync with the new local
// sprite ids, verify interaction_modes_count, and refresh the
// emulator + asset ownership. Never fails the stream — best effort.
try {
await reconcileImportedOfferIds();
await reconcileFurniDataWithItemsBase();
await verifyAndFixInteractionModesCount();
await ensureFurniOwnership();
await syncAssetsToGamedataBundle();
await rcon.updateCatalog();
await rcon.updateItems();
} catch {
/* best effort — post-import consolidation is non-fatal */
}
}, },
}); });
}, },
@@ -13,6 +13,7 @@ import {
importSingleFurni, importSingleFurni,
reconcileImportedOfferIds, reconcileImportedOfferIds,
syncAssetsToGamedataBundle, syncAssetsToGamedataBundle,
verifyAndFixInteractionModesCount,
} from "@/lib/services/furni-import"; } from "@/lib/services/furni-import";
import { rcon } from "@/lib/services/rcon"; import { rcon } from "@/lib/services/rcon";
import type { ImportSingleResult } from "@/types/furni"; import type { ImportSingleResult } from "@/types/furni";
@@ -223,8 +224,10 @@ export const POST = withAdmin(
let nitrosSynced: string[] = []; let nitrosSynced: string[] = [];
let iconsSynced: string[] = []; let iconsSynced: string[] = [];
let furniDataFixedIds = 0; let furniDataFixedIds = 0;
let furniDataFixedOfferIds = 0;
let furniDataMissing = 0; let furniDataMissing = 0;
let furniDataConflicts = 0; let furniDataConflicts = 0;
let interactionFixed = 0;
try { try {
offerIdsFixed = (await reconcileImportedOfferIds()).fixed; offerIdsFixed = (await reconcileImportedOfferIds()).fixed;
ownershipFixed = (await ensureFurniOwnership()).fixed; ownershipFixed = (await ensureFurniOwnership()).fixed;
@@ -233,8 +236,10 @@ export const POST = withAdmin(
iconsSynced = assetsSynced.copiedIcons; iconsSynced = assetsSynced.copiedIcons;
const furniReconcile = await reconcileFurniDataWithItemsBase(); const furniReconcile = await reconcileFurniDataWithItemsBase();
furniDataFixedIds = furniReconcile.fixedIds; furniDataFixedIds = furniReconcile.fixedIds;
furniDataFixedOfferIds = furniReconcile.fixedOfferIds;
furniDataMissing = furniReconcile.missing; furniDataMissing = furniReconcile.missing;
furniDataConflicts = furniReconcile.conflicts; furniDataConflicts = furniReconcile.conflicts;
interactionFixed = (await verifyAndFixInteractionModesCount()).fixed;
} catch (err) { } catch (err) {
console.warn( console.warn(
"[import-furni] Post-import reconcile/ownership failed:", "[import-furni] Post-import reconcile/ownership failed:",
@@ -252,8 +257,10 @@ export const POST = withAdmin(
nitrosSynced, nitrosSynced,
iconsSynced, iconsSynced,
furniDataFixedIds, furniDataFixedIds,
furniDataFixedOfferIds,
furniDataMissing, furniDataMissing,
furniDataConflicts, furniDataConflicts,
interactionFixed,
duration: Date.now() - startTime, duration: Date.now() - startTime,
}); });
File diff suppressed because it is too large. Load diff
+3
View File
@@ -83,6 +83,9 @@ export const CLASSNAME_RULES: Array<{
/** Determine the catalog category for a furniture item based on its classname and type. */ /** Determine the catalog category for a furniture item based on its classname and type. */
export function classifyFurni(classname: string, itemType: string): string { export function classifyFurni(classname: string, itemType: string): string {
// Wall items are authoritative by type — a prefix rule (rare_, val_, xmas_,
// …) must never pull a wall item out of the "walls" category.
if (itemType === "wallitem" || itemType === "i") return "walls";
for (const rule of CLASSNAME_RULES) { for (const rule of CLASSNAME_RULES) {
if (rule.test(classname, itemType)) return rule.cat; if (rule.test(classname, itemType)) return rule.cat;
} }
+5 -2
View File
@@ -382,9 +382,12 @@ export async function generateCatalogSql(
} }
} }
const price = autoPriceFurni(entry.classname); const price = autoPriceFurni(entry.classname);
const displayName = entry.publicName || entry.classname; // catalog_name must match items_base.item_name (the classname), exactly
// like the app's own import pipeline, so the studio's in-catalog joins
// and the emulator's item lookup stay consistent. offer_id is the item id
// (sprite id), not a literal '-1'.
statements.push( statements.push(
`INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) VALUES (${nextId}, ${pageId}, ${entry.itemId}, '${escSqlLiteral(displayName)}', ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, '-1', '');`, `INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) VALUES (${nextId}, ${pageId}, ${entry.itemId}, '${escSqlLiteral(entry.classname)}', ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${entry.itemId}, '');`,
); );
nextId++; nextId++;
generated++; generated++;
+14 -4
View File
@@ -383,6 +383,10 @@ export async function cloneSingleFurni(params: {
animationStates: nitroAnimationStatesCount(clonedNitroJson), animationStates: nitroAnimationStatesCount(clonedNitroJson),
}); });
const interactionModesCount = autoInteraction.interactionModesCount; const interactionModesCount = autoInteraction.interactionModesCount;
// The auto-detected interaction type (wired/gate/teleport/…) is real data
// (source furnidata + cloned .nitro), never a keyword guess — apply it so
// wired and mechanical furniture actually work on the emulator.
const interactionType = autoInteraction.interactionType;
let newId: number; let newId: number;
try { try {
@@ -393,7 +397,7 @@ export async function cloneSingleFurni(params: {
allow_stack, allow_sit, allow_lay, allow_walk, interaction_type, interaction_modes_count, customparams) allow_stack, allow_sit, allow_lay, allow_walk, interaction_type, interaction_modes_count, customparams)
VALUES VALUES
(${nextId}, ${nextId}, ${entry.name}, ${classname}, ${itemType}, ${entry.xdim}, ${entry.ydim}, ${stackHeight}, (${nextId}, ${nextId}, ${entry.name}, ${classname}, ${itemType}, ${entry.xdim}, ${entry.ydim}, ${stackHeight},
${allowStack}, ${entry.cansiton ? "1" : "0"}, ${entry.canlayon ? "1" : "0"}, ${entry.canstandon ? "1" : "0"}, 'default', ${interactionModesCount}, ${entry.customparams})`); ${allowStack}, ${entry.cansiton ? "1" : "0"}, ${entry.canlayon ? "1" : "0"}, ${entry.canstandon ? "1" : "0"}, ${interactionType}, ${interactionModesCount}, ${entry.customparams})`);
return nextId; return nextId;
}); });
} catch (err) { } catch (err) {
@@ -412,9 +416,15 @@ export async function cloneSingleFurni(params: {
}; };
} }
// FurnitureData entry — reuse the source's furnitype object, with our id. // FurnitureData entry — reuse the source's furnitype object, but with our id
// AND our offerid. The source's offerid points at the source hotel's sprite
// ids, which would silently break the emulator's catalog offer lookup.
onProgress?.("writing_furnidata"); onProgress?.("writing_furnidata");
const furniDataEntry = { ...entry, id: newId } as Record<string, unknown>; const furniDataEntry = {
...entry,
id: newId,
offerid: newId,
} as Record<string, unknown>;
if (deferFurniData) { if (deferFurniData) {
// Batch mode: the caller collects entries and appends them once at the end. // Batch mode: the caller collects entries and appends them once at the end.
} else { } else {
@@ -436,7 +446,7 @@ export async function cloneSingleFurni(params: {
await allocateCatalogItemId(async (nextCatalogId) => { await allocateCatalogItemId(async (nextCatalogId) => {
await db.execute(sql` await db.execute(sql`
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, '-1', '')`); VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
return nextCatalogId; return nextCatalogId;
}); });
} catch (err) { } catch (err) {
+18 -2
View File
@@ -447,6 +447,8 @@ export async function appendFurniEntriesBatch(
export interface FurniDataReconcileResult { export interface FurniDataReconcileResult {
/** Entries whose stale spriteId was corrected to the DB id. */ /** Entries whose stale spriteId was corrected to the DB id. */
fixedIds: number; fixedIds: number;
/** Entries whose stale offerid was corrected to the DB id. */
fixedOfferIds: number;
/** items_base rows with no matching furnitype entry (need re-import). */ /** items_base rows with no matching furnitype entry (need re-import). */
missing: number; missing: number;
/** spriteIds used by a different classname in the file; left untouched. */ /** spriteIds used by a different classname in the file; left untouched. */
@@ -458,6 +460,8 @@ export interface FurniDataReconcileResult {
* repair drift: * repair drift:
* - an entry matching the classname but carrying a stale spriteId is updated * - an entry matching the classname but carrying a stale spriteId is updated
* to the DB id (items_base is authoritative); * to the DB id (items_base is authoritative);
* - the same is done for a stale `offerid`, which must equal the spriteId so
* the emulator's catalog offer lookup stays in sync with the local ids;
* - rows missing entirely from the file are counted (they need a re-import * - rows missing entirely from the file are counted (they need a re-import
* or batch-regen, since building an entry requires the SWF/nitro metadata); * or batch-regen, since building an entry requires the SWF/nitro metadata);
* - genuine spriteId conflicts (id used by a different classname) are counted * - genuine spriteId conflicts (id used by a different classname) are counted
@@ -498,21 +502,33 @@ export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconc
} }
let fixedIds = 0; let fixedIds = 0;
let fixedOfferIds = 0;
let missing = 0; let missing = 0;
let conflicts = 0; let conflicts = 0;
const entryOfferId = (entry: Record<string, unknown>): number => {
const v = Number(entry.offerid);
return Number.isFinite(v) ? v : -1;
};
for (const row of rows) { for (const row of rows) {
const spriteId = row.id; const spriteId = row.id;
const existing = byId.get(spriteId); const existing = byId.get(spriteId);
if (existing) { if (existing) {
if (existing.entry.classname !== row.itemName) { if (existing.entry.classname !== row.itemName) {
conflicts++; conflicts++;
} else if (entryOfferId(existing.entry) !== spriteId) {
existing.entry.offerid = spriteId;
fixedOfferIds++;
} }
continue; continue;
} }
const byName = byClass.get(row.itemName); const byName = byClass.get(row.itemName);
if (byName) { if (byName) {
byName.entry.id = spriteId; byName.entry.id = spriteId;
if (entryOfferId(byName.entry) !== spriteId) {
byName.entry.offerid = spriteId;
}
byId.set(spriteId, byName); byId.set(spriteId, byName);
fixedIds++; fixedIds++;
} else { } else {
@@ -520,9 +536,9 @@ export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconc
} }
} }
if (fixedIds > 0) { if (fixedIds > 0 || fixedOfferIds > 0) {
await writeFurniData(furniData as Record<string, unknown>); await writeFurniData(furniData as Record<string, unknown>);
} }
return { fixedIds, missing, conflicts }; return { fixedIds, fixedOfferIds, missing, conflicts };
}); });
} }
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -206,7 +206,7 @@ async function writeSqlMigration(params: {
`INSERT INTO catalog_items`, `INSERT INTO catalog_items`,
` (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)`, ` (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)`,
`SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM catalog_items), p.id, @next_id, ${escapeSql(params.classname)},`, `SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM catalog_items), p.id, @next_id, ${escapeSql(params.classname)},`,
` ${params.price.credits}, ${params.price.points}, ${params.price.pointsType}, 1, 1, '-1', ''`, ` ${params.price.credits}, ${params.price.points}, ${params.price.pointsType}, 1, 1, @next_id, ''`,
`FROM catalog_pages p`, `FROM catalog_pages p`,
`WHERE p.caption_save = ${escapeSql(captionSave)};`, `WHERE p.caption_save = ${escapeSql(captionSave)};`,
"", "",
@@ -391,7 +391,7 @@ export async function uploadSingleFurni(params: {
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => { catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => {
await db.execute(sql` await db.execute(sql`
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, '-1', '')`); VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
return nextCatalogId; return nextCatalogId;
}); });
} catch (err) { } catch (err) {