- resolveGamedataFile: detect Windows drive/UNC paths explicitly instead of path.win32.isAbsolute (which is true for any /-prefixed path on Linux), so /nitro-assets URLs are no longer returned verbatim; add deployment gamedata root fallback (/var/www/Gamedata/config) and keep public/Gamedata/config. - effect/figure import dirs now resolve via site settings then the gamedata root bundled dir, instead of hardcoded public paths. - effect list falls back to the local EffectMap when the official habbo.com endpoint is unreachable, keeping the admin import page usable. - update staff smoke contract for db:migrate and instant=false (Cache Components migration).
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { resolveGamedataFile } from "@/lib/services/import/core/asset-paths";
|
|
import {
|
|
readGamedataJson,
|
|
withGamedataLock,
|
|
writeGamedataJsonAtomic,
|
|
} from "@/lib/services/import/core/gamedata-json";
|
|
import { siteSettings } from "@/lib/services/site-settings";
|
|
|
|
export interface FigureLibrary {
|
|
id: string;
|
|
revision: number;
|
|
parts?: Array<{ id: number; type: string }>;
|
|
}
|
|
|
|
interface FigureMapFile {
|
|
libraries: FigureLibrary[];
|
|
}
|
|
|
|
let pathOverride: string | null = null;
|
|
export function __setFigureMapPathForTests(p: string | null): void {
|
|
pathOverride = p;
|
|
}
|
|
|
|
export async function getFigureMapPath(): Promise<string> {
|
|
if (pathOverride) return pathOverride;
|
|
const url = await siteSettings.get(
|
|
"figuremap_url",
|
|
"/nitro-assets/gamedata/FigureMap.json",
|
|
);
|
|
return await resolveGamedataFile(
|
|
url ?? "/nitro-assets/gamedata/FigureMap.json",
|
|
"FigureMap.json",
|
|
);
|
|
}
|
|
|
|
export async function listFigureLibraries(): Promise<FigureLibrary[]> {
|
|
const file = await getFigureMapPath();
|
|
const data = await readGamedataJson<Partial<FigureMapFile>>(file);
|
|
return Array.isArray(data.libraries) ? data.libraries : [];
|
|
}
|
|
|
|
export async function mergeLibrary(lib: FigureLibrary): Promise<void> {
|
|
const file = await getFigureMapPath();
|
|
await withGamedataLock(file, async () => {
|
|
const data = await readGamedataJson<{ libraries?: FigureLibrary[] }>(file);
|
|
const libraries = Array.isArray(data.libraries) ? data.libraries : [];
|
|
const idx = libraries.findIndex((l) => l.id === lib.id);
|
|
if (idx >= 0) {
|
|
libraries[idx] = lib;
|
|
} else {
|
|
libraries.push(lib);
|
|
}
|
|
await writeGamedataJsonAtomic(file, { ...data, libraries });
|
|
});
|
|
}
|