fix(catalog): resolve classname candidates using public_name

This commit is contained in:
openhands committed 2026-09-07 19:15:35 +02:00
1 parent 8c47c3c158
commit ca6aa97eb2
5 files changed
+305 -211

No files matched your search

+26 -7
View File
@@ -77,8 +77,15 @@ export const NO_CATALOG_KINDS: ReadonlySet<CatalogItemKind> = new Set([
* files. Returns `.nitro` and icon candidates (most specific first):
* the exact classname, the star-variant base, the star→underscore name and the
* dot→underscore name (`post.it` → `post_it.nitro`).
*
* When `publicName` is provided it is treated as an alternative classname (many
* hotels store the real classname in `items_base.public_name` while `item_name`
* holds a display name). Candidates from both names are merged and deduplicated.
*/
export function assetNameCandidates(classname: string): {
export function assetNameCandidates(
classname: string,
publicName?: string,
): {
nitro: string[];
icon: string[];
} {
@@ -97,12 +104,24 @@ export function assetNameCandidates(classname: string): {
const starUnderscore = classname.replace(/\*/g, "_");
const dotUnderscore = classname.replace(/\./g, "_");
const bases = [classname, starBase, dotUnderscore, starUnderscore];
// Also try public_name when it looks like a real classname (no spaces,
// not empty, not "0" which some hotels use as a "no value" marker).
if (
publicName &&
publicName !== classname &&
!publicName.includes(" ") &&
publicName !== "0"
) {
const pnBase = publicName.split("*")[0];
const pnStar = publicName.replace(/\*/g, "_");
const pnDot = publicName.replace(/\./g, "_");
bases.push(publicName, pnBase, pnDot, pnStar);
}
return {
nitro: unique([classname, starBase, dotUnderscore, starUnderscore]).map(
(n) => `${n}.nitro`,
),
icon: unique([classname, starUnderscore, dotUnderscore, starBase]).map(
(n) => `${n}_icon.png`,
),
nitro: unique(bases).map((n) => `${n}.nitro`),
icon: unique(bases).map((n) => `${n}_icon.png`),
};
}