Gitea Actions Runner Test / test-job (push) Successful in 1s
CI / check (push) Successful in 29s
CI / tests-unit (push) Failing after 1m37s
CI / tests-integration (push) Successful in 1m37s
CI / tests-ui (push) Successful in 2m17s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Every bundle the CMS writes — upload, clone, sync, repair and the pet / effect / figure importers — now lands as `<classname>.hab`, the extension this deployment's renderer asks for. `.hab` and `.nitro` are the same container, so an upload of either extension is accepted. Resolution goes through one module, src/lib/furni/bundle-file.ts, so nothing has to know the extension twice. Every existence check probes `.hab` first and falls back to `.nitro`: the on-disk asset set is still predominantly `.nitro`, and without the fallback Studio would report every imported item as missing and the cleanup scan would classify 18k live bundles as fake leftovers. Downloads are unchanged — Habbo's CDN and every configured clone source still serve `.nitro`, so the conversion happens on write, not on request. Deliberately unchanged: the staged-attachment store in furni-attachment.ts keys on a UUID and never reaches the client, so renaming it would break in-flight recovery jobs. Adds scripts/migrate-nitro-to-hab.ts to rename the existing asset set. It refuses to run without --dry-run or --yes, never overwrites an existing .hab, never deletes, and is idempotent. Note: renderer-config.json lives outside this repo and was patched to .hab separately; that file is served with a 30-day max-age, so returning clients need a cms-client cache purge to pick the change up.
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
const CLASSNAME_CHAR_RE = /^[a-z0-9_*\-.]+$/;
|
|
|
|
export function getBaseClassname(classname: string): string {
|
|
const star = classname.indexOf("*");
|
|
return star >= 0 ? classname.substring(0, star) : classname;
|
|
}
|
|
|
|
export function getSafeClassnameStem(classname: string): string {
|
|
return classname.replace(/\*/g, "_");
|
|
}
|
|
|
|
export function getIconFileName(classname: string): string {
|
|
return `${getSafeClassnameStem(classname)}_icon.png`;
|
|
}
|
|
|
|
export function getSwfFileName(classname: string): string {
|
|
return `${getBaseClassname(classname)}.swf`;
|
|
}
|
|
|
|
/**
|
|
* Extension locally stored furniture bundles are written with. This deployment's
|
|
* Nitro client requests `<classname>.hab`, so that is what new imports produce.
|
|
*/
|
|
export const LOCAL_BUNDLE_EXT = ".hab";
|
|
|
|
/**
|
|
* Extension remote sources serve bundles with. Upstream (Habbo's CDN and every
|
|
* configured clone source) keeps shipping `.nitro`, so download URLs are built
|
|
* with this and only re-written to `LOCAL_BUNDLE_EXT` once they land on disk.
|
|
*/
|
|
export const SOURCE_BUNDLE_EXT = ".nitro";
|
|
|
|
/** Both extensions a local bundle may carry, newest convention first. */
|
|
export const LOCAL_BUNDLE_EXTS = [LOCAL_BUNDLE_EXT, SOURCE_BUNDLE_EXT] as const;
|
|
|
|
/** Primary local bundle name — `.hab` wins over a legacy `.nitro`. */
|
|
export function getNitroFileName(classname: string): string {
|
|
return `${getBaseClassname(classname)}${LOCAL_BUNDLE_EXT}`;
|
|
}
|
|
|
|
/** Every local file name this classname's bundle may be stored under. */
|
|
export function getLocalBundleFileNames(classname: string): string[] {
|
|
const base = getBaseClassname(classname);
|
|
return LOCAL_BUNDLE_EXTS.map((ext) => `${base}${ext}`);
|
|
}
|
|
|
|
/** File name for an explicit extension — use `SOURCE_BUNDLE_EXT` for URLs. */
|
|
export function getBundleFileName(
|
|
classname: string,
|
|
ext: string = LOCAL_BUNDLE_EXT,
|
|
): string {
|
|
return `${getBaseClassname(classname)}${ext}`;
|
|
}
|
|
|
|
export function normalizeClassname(raw: string): string {
|
|
return raw.trim().toLowerCase();
|
|
}
|
|
|
|
export function isValidClassname(classname: string): boolean {
|
|
if (!classname) return false;
|
|
return CLASSNAME_CHAR_RE.test(classname);
|
|
}
|
|
|
|
/**
|
|
* Asset-name safety check for values that become file names (swf / nitro / icon).
|
|
*
|
|
* The real rule is "cannot escape the directory": no path separators, so `../`
|
|
* is structurally impossible. Case matters here — classnames in gamedata are
|
|
* mixed-case (`recycler_kintsugiB`), so this must not be folded to lowercase the
|
|
* way `isValidClassname` presumes.
|
|
*/
|
|
const ASSET_NAME_RE = /^[\w*.-]+$/;
|
|
|
|
export function isSafeAssetName(name: string): boolean {
|
|
const trimmed = name.trim();
|
|
if (!trimmed) return false;
|
|
if (!ASSET_NAME_RE.test(trimmed)) return false;
|
|
return !trimmed.includes("..");
|
|
}
|
|
|
|
export const LOCAL_ICON_URL_PREFIX = "/swf/dcr/hof_furni/icons/";
|
|
|
|
export function getLocalIconUrl(classname: string): string {
|
|
return `${LOCAL_ICON_URL_PREFIX}${encodeURIComponent(getIconFileName(classname))}`;
|
|
}
|
|
|
|
export function getHabboCdnIconUrl(
|
|
classname: string,
|
|
revision: number,
|
|
): string {
|
|
const base = getBaseClassname(classname);
|
|
return `https://images.habbo.com/dcr/hof_furni/${revision}/${encodeURIComponent(base)}_icon.png`;
|
|
}
|