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 {
appendFurniEntriesBatch,
appendFurniEntry,
reconcileFurniDataWithItemsBase,
} 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 { rcon } from "@/lib/services/rcon";
interface BatchItem {
classname: string;
@@ -126,6 +134,22 @@ export const POST = withAdmin(
`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,
reconcileImportedOfferIds,
syncAssetsToGamedataBundle,
verifyAndFixInteractionModesCount,
} from "@/lib/services/furni-import";
import { rcon } from "@/lib/services/rcon";
import type { ImportSingleResult } from "@/types/furni";
@@ -223,8 +224,10 @@ export const POST = withAdmin(
let nitrosSynced: string[] = [];
let iconsSynced: string[] = [];
let furniDataFixedIds = 0;
let furniDataFixedOfferIds = 0;
let furniDataMissing = 0;
let furniDataConflicts = 0;
let interactionFixed = 0;
try {
offerIdsFixed = (await reconcileImportedOfferIds()).fixed;
ownershipFixed = (await ensureFurniOwnership()).fixed;
@@ -233,8 +236,10 @@ export const POST = withAdmin(
iconsSynced = assetsSynced.copiedIcons;
const furniReconcile = await reconcileFurniDataWithItemsBase();
furniDataFixedIds = furniReconcile.fixedIds;
furniDataFixedOfferIds = furniReconcile.fixedOfferIds;
furniDataMissing = furniReconcile.missing;
furniDataConflicts = furniReconcile.conflicts;
interactionFixed = (await verifyAndFixInteractionModesCount()).fixed;
} catch (err) {
console.warn(
"[import-furni] Post-import reconcile/ownership failed:",
@@ -252,8 +257,10 @@ export const POST = withAdmin(
nitrosSynced,
iconsSynced,
furniDataFixedIds,
furniDataFixedOfferIds,
furniDataMissing,
furniDataConflicts,
interactionFixed,
duration: Date.now() - startTime,
});
+42 -10
View File
@@ -24,6 +24,7 @@ import {
reconcileImportedOfferIds,
resetCatalogPageCache,
syncAssetsToGamedataBundle,
verifyAndFixInteractionModesCount,
} from "@/lib/services/furni-import";
import { getOfficialHabboFurnidata } from "@/lib/services/habbo-furnidata-cache";
import { listFurniture } from "@/lib/services/habbofurni";
@@ -103,15 +104,14 @@ export const GET = withAdmin(
// Stats endpoint
const action = request.nextUrl.searchParams.get("action");
if (action === "stats") {
const [totalResult, catalogResult, nitroMissingResult] =
const [totalResult, catalogResult, allIdsResult, referencedResult] =
await Promise.all([
db.execute(sql`SELECT COUNT(*) as cnt FROM items_base`),
db.execute(
sql`SELECT COUNT(DISTINCT item_ids) as cnt FROM catalog_items`,
),
db.execute(
sql`SELECT COUNT(*) as cnt FROM items_base WHERE item_name NOT IN (SELECT catalog_name FROM catalog_items)`,
),
db.execute(sql`SELECT id FROM items_base`),
db.execute(sql`SELECT item_ids FROM catalog_items`),
]);
const totalInDb = Number(
@@ -120,15 +120,34 @@ export const GET = withAdmin(
const inCatalog = Number(
(catalogResult as unknown as [[{ cnt: bigint }], unknown])[0][0].cnt,
);
const notInCatalog = Number(
(nitroMissingResult as unknown as [[{ cnt: bigint }], unknown])[0][0]
.cnt,
);
// An item is "in the catalog" when its items_base id is referenced by
// any catalog_items.item_ids (the canonical link — catalog_name can be
// a translated display name, so matching on it is unreliable).
const allIds = (
allIdsResult as unknown as [Array<{ id: number }>, unknown]
)[0].map((r) => Number(r.id));
const referenced = new Set<number>();
for (const row of (
referencedResult as unknown as [
Array<{ item_ids: string | null }>,
unknown,
]
)[0]) {
for (const part of String(row.item_ids ?? "").split(/[;,]/)) {
const n = Number(part.trim());
if (Number.isFinite(n) && n > 0) referenced.add(n);
}
}
const notInCatalog = allIds.filter((id) => !referenced.has(id)).length;
// Count missing .nitro files by checking filesystem
const [importedItems] = (await db.execute(sql`
SELECT ib.item_name FROM items_base ib
INNER JOIN catalog_items ci ON ci.catalog_name = ib.item_name
WHERE EXISTS (
SELECT 1 FROM catalog_items ci
WHERE FIND_IN_SET(ib.id, REPLACE(ci.item_ids, ';', ',')) > 0
)
LIMIT 10000
`)) as unknown as [Array<{ item_name: string }>, unknown];
@@ -159,7 +178,10 @@ export const GET = withAdmin(
const [importedItems] = (await db.execute(sql`
SELECT ib.item_name, ib.public_name, ib.sprite_id, ib.type FROM items_base ib
INNER JOIN catalog_items ci ON ci.catalog_name = ib.item_name
WHERE EXISTS (
SELECT 1 FROM catalog_items ci
WHERE FIND_IN_SET(ib.id, REPLACE(ci.item_ids, ';', ',')) > 0
)
`)) as unknown as [
Array<{
item_name: string;
@@ -419,6 +441,9 @@ export const POST = withAdmin(
// Verify the furnidata matches the DB ids
const furniReconcile = await reconcileFurniDataWithItemsBase();
// Verify + fix interaction_modes_count once for the whole batch
const verification = await verifyAndFixInteractionModesCount();
const succeeded = results.filter((r) => r.ok).length;
const failed = results.filter((r) => !r.ok).length;
@@ -432,8 +457,10 @@ export const POST = withAdmin(
nitrosSynced: assetsSynced.copiedNitros,
iconsSynced: assetsSynced.copiedIcons,
furniDataFixedIds: furniReconcile.fixedIds,
furniDataFixedOfferIds: furniReconcile.fixedOfferIds,
furniDataMissing: furniReconcile.missing,
furniDataConflicts: furniReconcile.conflicts,
interactionFixed: verification.fixed,
});
}
@@ -495,6 +522,9 @@ export const POST = withAdmin(
// Verify the furnidata matches the DB ids
const furniReconcile = await reconcileFurniDataWithItemsBase();
// Verify + fix interaction_modes_count (single consolidated pass)
const verification = await verifyAndFixInteractionModesCount();
logAudit({
userId: ctx.session.user.id,
action: "furni_import",
@@ -520,8 +550,10 @@ export const POST = withAdmin(
nitrosSynced: assetsSynced.copiedNitros,
iconsSynced: assetsSynced.copiedIcons,
furniDataFixedIds: furniReconcile.fixedIds,
furniDataFixedOfferIds: furniReconcile.fixedOfferIds,
furniDataMissing: furniReconcile.missing,
furniDataConflicts: furniReconcile.conflicts,
interactionFixed: verification.fixed,
spriteCount: result.spriteCount,
warnings: result.warnings,
});