feat: relocate import tools into studio and harden catalog/furnidata integrity
CI / check (push) Failing after 26s
CI / release (push) Skipped
CI / deploy (push) Skipped

- Move /admin/import/* tools under /admin/studio/* and add studio nav, layout and tabs
- Add shared catalog maintenance panel plus a /admin/studio/maintenance tab
- Make furnidata reconciliation overwrite conflicting entries with the
  DB-authoritative items_base classname/id (surfaced via fixedConflicts)
- Add furnidata_translate_enabled setting to skip the heavy localized
  furnidata build during import (manual build-languages still forces it)
- Update staff smoke contract test for the studio hub
This commit is contained in:
openhands committed 2026-08-24 17:13:03 +02:00
1 parent c2e61dc324
commit c7ba04bda1
36 files changed
+616 -2835

No files matched your search

+32 -3
View File
@@ -41,6 +41,22 @@ export const FURNIDATA_LANGUAGES = [
export type FurnidataLang = (typeof FURNIDATA_LANGUAGES)[number]["lang"];
/**
* Master switch for FurnitureData localization. Rebuilding the per-language
* files deep-clones the 100k+ entry master 13× and hits LibreTranslate, which
* can spike RAM/CPU on every import. Admins can disable it in settings to skip
* the work entirely (the master FurnitureData.json is still written by the
* import itself). The manual "build languages" action passes `force` to run
* regardless.
*/
async function translationEnabled(): Promise<boolean> {
try {
return await siteSettings.getBool("furnidata_translate_enabled", true);
} catch {
return true;
}
}
export interface LanguageFileResult {
lang: string;
hotel: string;
@@ -415,9 +431,15 @@ function cloneFurniData(
* translation exists for that classname. Runs under the furnidata lock so it
* never interleaves with concurrent imports.
*/
export async function buildLocalizedFurniDataFiles(): Promise<
LanguageFileResult[]
> {
export async function buildLocalizedFurniDataFiles(
force = false,
): Promise<LanguageFileResult[]> {
if (!force && !(await translationEnabled())) {
logger.debug(
"[furni-i18n] FurnitureData translation disabled by setting; skipping localized build.",
);
return [];
}
return withFurniDataLock(async () => {
const master = (await readFurniData()) as Record<
string,
@@ -554,8 +576,15 @@ export async function buildLocalizedFurniDataFiles(): Promise<
*/
export async function patchLocalizedFurniDataEntries(
entries: Array<{ classname: string; name?: string; description?: string }>,
force = false,
): Promise<LanguageFileResult[]> {
if (entries.length === 0) return [];
if (!force && !(await translationEnabled())) {
logger.debug(
"[furni-i18n] FurnitureData translation disabled by setting; skipping localized patch.",
);
return [];
}
return withFurniDataLock(async () => {
const maps = await Promise.all(
+32 -7
View File
@@ -485,7 +485,12 @@ export interface FurniDataReconcileResult {
normalizedIds: 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. */
/** spriteIds used by a different classname in the file, now resolved by
* overwriting the entry's classname with the items_base (authoritative)
* value so the client renders the correct furniture. */
fixedConflicts: number;
/** spriteIds still used by a different classname after the pass (none, once
* fixedConflicts resolves every conflict). */
conflicts: number;
}
@@ -498,8 +503,10 @@ export interface FurniDataReconcileResult {
* 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
* but never auto-fixed.
* - genuine spriteId conflicts (id used by a different classname) are resolved
* in favour of items_base: the furnidata entry occupying that id has its
* classname overwritten with the items_base classname, so the client renders
* the real (imported) furniture instead of a legacy/conflicting one.
*/
export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconcileResult> {
return withFurniDataLock(async () => {
@@ -539,7 +546,8 @@ export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconc
let fixedOfferIds = 0;
let normalizedIds = 0;
let missing = 0;
let conflicts = 0;
let fixedConflicts = 0;
const conflicts = 0;
const entryOfferId = (entry: Record<string, unknown>): number => {
const v = Number(entry.offerid);
@@ -551,7 +559,17 @@ export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconc
const existing = byId.get(spriteId);
if (existing) {
if (existing.entry.classname !== row.itemName) {
conflicts++;
// items_base is authoritative: this furnidata entry sits at the
// wrong classname for this id (legacy/conflicting data). Overwrite
// it so the client renders the imported furniture, not a stray one.
const displaced = String(existing.entry.classname ?? "");
existing.entry.classname = row.itemName;
existing.entry.id = spriteId;
existing.entry.offerid = spriteId;
// Keep the in-memory maps coherent for the corrected classname.
byClass.set(row.itemName, existing);
if (displaced) byClass.delete(displaced);
fixedConflicts++;
} else if (entryOfferId(existing.entry) !== spriteId) {
existing.entry.offerid = spriteId;
fixedOfferIds++;
@@ -589,10 +607,17 @@ export async function reconcileFurniDataWithItemsBase(): Promise<FurniDataReconc
}
}
if (fixedIds > 0 || fixedOfferIds > 0) {
if (fixedIds > 0 || fixedOfferIds > 0 || fixedConflicts > 0) {
await writeFurniData(furniData as Record<string, unknown>);
}
return { fixedIds, fixedOfferIds, normalizedIds, missing, conflicts };
return {
fixedIds,
fixedOfferIds,
normalizedIds,
missing,
fixedConflicts,
conflicts,
};
});
}
+6 -4
View File
@@ -180,8 +180,8 @@ describeGuard("live furni import / catalog ID consistency (sandbox DB)", () => {
const before = buildMaps(await readFurniData());
// Genuine id conflicts (our spriteId is owned by a different classname
// in the file) are left untouched by design — they are a separate
// pre-existing data problem, not part of this fix.
// in the file) are resolved in favour of items_base: the entry keeps its
// id but its classname is overwritten with the items_base classname.
let conflicts = 0;
let missing = 0;
for (const row of rows) {
@@ -205,7 +205,8 @@ describeGuard("live furni import / catalog ID consistency (sandbox DB)", () => {
const result = await reconcileFurniDataWithItemsBase();
expect(result.fixedIds).toBe(idMisBefore);
expect(result.conflicts).toBe(conflicts);
expect(result.fixedConflicts).toBe(conflicts);
expect(result.conflicts).toBe(0);
expect(result.missing).toBe(missing);
// Mirror the function's contract exactly: rows whose id IS keyed in the
@@ -218,7 +219,8 @@ describeGuard("live furni import / catalog ID consistency (sandbox DB)", () => {
// furnidata file can only hold one id per classname, so a duplicate
// classname can never satisfy this invariant for all its rows. Those
// are repaired by the dedicated duplicate-classname tool, not by this
// function. Genuine id conflicts are likewise out of scope.
// function. Genuine id conflicts are now resolved by overwriting the
// entry's classname with the items_base value (see fixedConflicts).
const dupClassnames = new Map<string, number>();
for (const row of rows)
dupClassnames.set(