fix(import): make effects and figure/clothing import work on deployment
- 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).
This commit is contained in:
1 parent
694a24c791
commit
dd708a64fb
10 files changed
+172
-56
No files matched your search
@@ -1,9 +1,14 @@
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/lib/services/furni-asset-dirs", () => ({
|
||||
getGamedataRoot: vi.fn(async () => ""),
|
||||
}));
|
||||
|
||||
import { resolveGamedataFile } from "./asset-paths";
|
||||
|
||||
describe("resolveGamedataFile", () => {
|
||||
it("uses absolute external paths as-is", () => {
|
||||
it("uses absolute external paths as-is", async () => {
|
||||
const absolutePath = path.win32.join(
|
||||
"E:\\",
|
||||
"Users",
|
||||
@@ -16,7 +21,7 @@ describe("resolveGamedataFile", () => {
|
||||
"FigureMap.json",
|
||||
);
|
||||
|
||||
expect(resolveGamedataFile(absolutePath, "FigureMap.json")).toBe(
|
||||
expect(await resolveGamedataFile(absolutePath, "FigureMap.json")).toBe(
|
||||
absolutePath,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { getGamedataRoot } from "@/lib/services/furni-asset-dirs";
|
||||
|
||||
// The CMS default gamedata JSON paths point under public/nitro-assets/gamedata/,
|
||||
// but this deployment keeps the gamedata JSON (FigureMap/FigureData/EffectMap…)
|
||||
// under public/Gamedata/config/. `resolveGamedataFile` falls back there when the
|
||||
// under the gamedata root (public/Gamedata/config/ or the deployment's
|
||||
// `/var/www/Gamedata/config/`). `resolveGamedataFile` falls back there when the
|
||||
// configured path is absent, so importers read AND write the real file — no
|
||||
// manual setting required. (Bundled .nitro stay under public/nitro-assets/bundled,
|
||||
// the client's served asset dir — see *_NITRO_DIR consts in the import services.)
|
||||
// manual setting required. (Bundled .nitro stay under the gamedata root's
|
||||
// `bundled/` dir, the location the Nitro client loads from.)
|
||||
|
||||
function pub(...segs: string[]): string {
|
||||
return path.join(/*turbopackIgnore: true*/ process.cwd(), "public", ...segs);
|
||||
@@ -14,18 +16,39 @@ function pub(...segs: string[]): string {
|
||||
|
||||
/**
|
||||
* Resolve a gamedata JSON file from a `*_url` setting value (e.g.
|
||||
* `/nitro-assets/gamedata/FigureMap.json`). Falls back to
|
||||
* `public/Gamedata/config/<fallbackName>` if the configured path is absent.
|
||||
* Returns the configured path when neither exists (write target for fresh setups).
|
||||
* `/nitro-assets/gamedata/FigureMap.json`). Falls back to the deployment's
|
||||
* gamedata root `config/` dir (then `public/Gamedata/config/`) when the
|
||||
* configured path is absent. Returns the configured path when neither exists
|
||||
* (write target for fresh setups).
|
||||
*/
|
||||
export function resolveGamedataFile(url: string, fallbackName: string): string {
|
||||
if (
|
||||
path.win32.isAbsolute(url) ||
|
||||
(path.isAbsolute(url) && !url.startsWith("/"))
|
||||
)
|
||||
export async function resolveGamedataFile(
|
||||
url: string,
|
||||
fallbackName: string,
|
||||
): Promise<string> {
|
||||
// A Windows drive/UNC path (e.g. configured on a Windows dev machine) is
|
||||
// used as-is. Note: path.win32.isAbsolute('/foo') is true on Linux, so we
|
||||
// match the drive/UNC prefix explicitly instead of delegating to it —
|
||||
// otherwise web paths like `/nitro-assets/gamedata/FigureMap.json` would be
|
||||
// mistaken for absolute filesystem paths and returned verbatim.
|
||||
if (/^[a-zA-Z]:[\\/]/.test(url) || url.startsWith("\\\\")) return url;
|
||||
// A real, existing absolute filesystem path is used as-is.
|
||||
if (path.isAbsolute(url) && existsSync(/*turbopackIgnore: true*/ url)) {
|
||||
return url;
|
||||
}
|
||||
const configured = pub(url.replace(/^\/+/, ""));
|
||||
if (existsSync(/*turbopackIgnore: true*/ configured)) return configured;
|
||||
|
||||
// Deployment gamedata root (e.g. /var/www/Gamedata/config/…).
|
||||
const gamedataRoot = await getGamedataRoot();
|
||||
if (gamedataRoot) {
|
||||
const rootConfig = path.join(
|
||||
/*turbopackIgnore: true*/ gamedataRoot,
|
||||
"config",
|
||||
fallbackName,
|
||||
);
|
||||
if (existsSync(/*turbopackIgnore: true*/ rootConfig)) return rootConfig;
|
||||
}
|
||||
|
||||
const gamedata = pub("Gamedata", "config", fallbackName);
|
||||
if (existsSync(/*turbopackIgnore: true*/ gamedata)) return gamedata;
|
||||
return configured;
|
||||
|
||||
Reference in new issue
Block a user