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

+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. */
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) {
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 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(
`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++;
generated++;
+14 -4
View File
@@ -383,6 +383,10 @@ export async function cloneSingleFurni(params: {
animationStates: nitroAnimationStatesCount(clonedNitroJson),
});
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;
try {
@@ -393,7 +397,7 @@ export async function cloneSingleFurni(params: {
allow_stack, allow_sit, allow_lay, allow_walk, interaction_type, interaction_modes_count, customparams)
VALUES
(${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;
});
} 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");
const furniDataEntry = { ...entry, id: newId } as Record<string, unknown>;
const furniDataEntry = {
...entry,
id: newId,
offerid: newId,
} as Record<string, unknown>;
if (deferFurniData) {
// Batch mode: the caller collects entries and appends them once at the end.
} else {
@@ -436,7 +446,7 @@ export async function cloneSingleFurni(params: {
await allocateCatalogItemId(async (nextCatalogId) => {
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)
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;
});
} catch (err) {
+18 -2
View File
@@ -447,6 +447,8 @@ export async function appendFurniEntriesBatch(
export interface FurniDataReconcileResult {
/** Entries whose stale spriteId was corrected to the DB id. */
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). */
missing: number;
/** spriteIds used by a different classname in the file; left untouched. */
@@ -458,6 +460,8 @@ export interface FurniDataReconcileResult {
* repair drift:
* - an entry matching the classname but carrying a stale spriteId is updated
* 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
* or batch-regen, since building an entry requires the SWF/nitro metadata);
* - 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 fixedOfferIds = 0;
let missing = 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) {
const spriteId = row.id;
const existing = byId.get(spriteId);
if (existing) {
if (existing.entry.classname !== row.itemName) {
conflicts++;
} else if (entryOfferId(existing.entry) !== spriteId) {
existing.entry.offerid = spriteId;
fixedOfferIds++;
}
continue;
}
const byName = byClass.get(row.itemName);
if (byName) {
byName.entry.id = spriteId;
if (entryOfferId(byName.entry) !== spriteId) {
byName.entry.offerid = spriteId;
}
byId.set(spriteId, byName);
fixedIds++;
} 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>);
}
return { fixedIds, missing, conflicts };
return { fixedIds, fixedOfferIds, missing, conflicts };
});
}
+47 -46
View File
@@ -544,15 +544,22 @@ export async function importSingleFurni(params: {
.from(ItemsBase)
.where(eq(ItemsBase.itemName, classname))
.limit(1);
if (existsByName) {
if (!updateExisting) {
return {
ok: false,
warnings,
error: `Item "${classname}" already exists (id: ${existsByName.id})`,
};
}
// Update existing item - fall through to update logic
if (existsByName && !updateExisting) {
return {
ok: false,
warnings,
error: `Item "${classname}" already exists (id: ${existsByName.id})`,
};
}
if (existsByName && existsByName.id !== originalId) {
// The classname already occupies a different spriteId. Reassigning the
// id would orphan every reference (catalog item_ids, player items,
// furnidata), so this can never be an "update".
return {
ok: false,
warnings,
error: `Item "${classname}" already exists with id ${existsByName.id} — cannot reassign to spriteId ${originalId}`,
};
}
const [existsById] = await db
.select({ itemName: ItemsBase.itemName })
@@ -560,16 +567,17 @@ export async function importSingleFurni(params: {
.where(eq(ItemsBase.id, originalId))
.limit(1);
if (existsById && (!existsByName || existsById.itemName !== classname)) {
if (!updateExisting) {
return {
ok: false,
warnings,
error: `spriteId ${originalId} already used by "${existsById.itemName}"`,
};
}
// Update existing item - fall through to update logic
// The spriteId is owned by a different classname. Even with
// updateExisting this is a genuine conflict, not an update.
return {
ok: false,
warnings,
error: `spriteId ${originalId} already used by "${existsById.itemName}"`,
};
}
const isUpdate = !!existsByName;
// ── Check if spriteId already used in FurnitureData.json ──
const takenBy = await findFurniDataIdConflict(originalId, classname);
if (takenBy && !updateExisting) {
@@ -604,18 +612,25 @@ export async function importSingleFurni(params: {
// ── Insert into DB with enriched data ──────────────────────────────
onProgress?.("writing_db");
try {
// NOTE: live Arcturus `items_base` has no description/revision/rare columns —
// those metadata fields are persisted in FurnitureData.json (see entry below),
// not in the DB. Inserting them here throws "Unknown column 'description'".
await db.execute(sql`
INSERT INTO items_base (id, sprite_id, public_name, item_name, type)
VALUES (${spriteId}, ${spriteId}, ${bestName}, ${classname}, ${itemType})
`);
if (isUpdate) {
// NOTE: live Arcturus `items_base` has no description/revision/rare columns —
// those metadata fields are persisted in FurnitureData.json (see entry below),
// not in the DB. Only refresh the columns this import manages.
await db.execute(sql`
UPDATE items_base SET sprite_id = ${spriteId}, public_name = ${bestName}, item_name = ${classname}, type = ${itemType}
WHERE id = ${spriteId}
`);
} else {
await db.execute(sql`
INSERT INTO items_base (id, sprite_id, public_name, item_name, type)
VALUES (${spriteId}, ${spriteId}, ${bestName}, ${classname}, ${itemType})
`);
}
} catch (err) {
return {
ok: false,
warnings,
error: `DB insert failed: ${(err as Error).message}`,
error: `DB ${isUpdate ? "update" : "insert"} failed: ${(err as Error).message}`,
};
}
@@ -995,23 +1010,6 @@ export async function importSingleFurni(params: {
warnings.push("Catalog entry creation failed");
}
// Verify and fix interaction_modes_count for all furniture
try {
const verification = await verifyAndFixInteractionModesCount();
if (verification.fixed > 0) {
warnings.push(
`Fixed interaction_modes_count for ${verification.fixed} of ${verification.checked} items`,
);
}
for (const err of verification.errors) {
warnings.push(`Interaction modes verification: ${err}`);
}
} catch (err) {
warnings.push(
`Interaction modes verification failed: ${(err as Error).message}`,
);
}
return {
ok: true,
itemId: spriteId,
@@ -1193,11 +1191,13 @@ export async function deleteImportedItem(classname: string): Promise<{
starIdx !== -1 ? classname.substring(0, starIdx) : classname;
const iconFileName = classname.replace(/\*/g, "_");
// 1. Delete catalog_items
// 1. Delete catalog_items — match by the canonical item_ids link only.
// catalog_name may have been translated to a public name, so adding a
// name condition would silently leave an orphaned catalog row behind.
try {
const itemIdStr = String(spriteId);
await db.execute(
sql`DELETE FROM catalog_items WHERE item_ids = ${itemIdStr} AND catalog_name = ${classname}`,
sql`DELETE FROM catalog_items WHERE item_ids = ${itemIdStr}`,
);
} catch (err) {
errors.push(`catalog_items: ${(err as Error).message}`);
@@ -1361,10 +1361,11 @@ export async function rollbackFurniImport(
const errorsForItem: string[] = [];
// 1. Delete from catalog_items
// 1. Delete from catalog_items — match by the canonical item_ids link only
// (catalog_name may be a translated display name).
try {
await db.execute(
sql`DELETE FROM catalog_items WHERE item_ids = ${String(item.spriteId)} AND catalog_name = ${item.classname}`,
sql`DELETE FROM catalog_items WHERE item_ids = ${String(item.spriteId)}`,
);
} catch (err) {
errorsForItem.push(`catalog_items: ${(err as Error).message}`);
+2 -2
View File
@@ -206,7 +206,7 @@ async function writeSqlMigration(params: {
`INSERT INTO catalog_items`,
` (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)},`,
` ${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`,
`WHERE p.caption_save = ${escapeSql(captionSave)};`,
"",
@@ -391,7 +391,7 @@ export async function uploadSingleFurni(params: {
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => {
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)
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;
});
} catch (err) {