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
@@ -4,6 +4,12 @@ import { describe, expect, it, vi } from "vitest";
|
|||||||
vi.mock("@/lib/services/import/core/download", () => ({
|
vi.mock("@/lib/services/import/core/download", () => ({
|
||||||
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
||||||
}));
|
}));
|
||||||
|
vi.mock("@/lib/services/site-settings", () => ({
|
||||||
|
siteSettings: { get: vi.fn(async () => "") },
|
||||||
|
}));
|
||||||
|
vi.mock("@/lib/services/furni-asset-dirs", () => ({
|
||||||
|
getGamedataRoot: vi.fn(async () => ""),
|
||||||
|
}));
|
||||||
vi.mock("@/lib/services/effect-source", () => ({
|
vi.mock("@/lib/services/effect-source", () => ({
|
||||||
resolveEffectSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
resolveEffectSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
||||||
listOfficialEffects: vi.fn(async () => []),
|
listOfficialEffects: vi.fn(async () => []),
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import {
|
|||||||
mergeEffect,
|
mergeEffect,
|
||||||
removeEffect,
|
removeEffect,
|
||||||
} from "@/lib/services/effectmap";
|
} from "@/lib/services/effectmap";
|
||||||
|
import { getGamedataRoot } from "@/lib/services/furni-asset-dirs";
|
||||||
import { downloadFile } from "@/lib/services/import/core/download";
|
import { downloadFile } from "@/lib/services/import/core/download";
|
||||||
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
import { convertSwfToNitro } from "@/lib/services/swf-to-nitro";
|
import { convertSwfToNitro } from "@/lib/services/swf-to-nitro";
|
||||||
import type {
|
import type {
|
||||||
EffectListItem,
|
EffectListItem,
|
||||||
@@ -17,18 +19,40 @@ import type {
|
|||||||
ImportEffectResult,
|
ImportEffectResult,
|
||||||
} from "@/types/effects";
|
} from "@/types/effects";
|
||||||
|
|
||||||
export const EFFECT_NITRO_DIR = path.join(
|
const EFFECT_NITRO_DIR_FALLBACK = path.join(
|
||||||
/*turbopackIgnore: true*/ process.cwd(),
|
/*turbopackIgnore: true*/ process.cwd(),
|
||||||
"public/nitro-assets/bundled/effect",
|
"public/nitro-assets/bundled/effect",
|
||||||
);
|
);
|
||||||
export const EFFECT_SWF_DIR = path.join(
|
const EFFECT_SWF_DIR_FALLBACK = path.join(
|
||||||
/*turbopackIgnore: true*/ process.cwd(),
|
/*turbopackIgnore: true*/ process.cwd(),
|
||||||
"public/swf/gordon",
|
"public/swf/gordon",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
async function getEffectNitroDir(): Promise<string> {
|
||||||
|
const configured = (
|
||||||
|
(await siteSettings.get("effect_nitro_dir", "")) ?? ""
|
||||||
|
).trim();
|
||||||
|
if (configured) return configured;
|
||||||
|
const gamedataRoot = await getGamedataRoot();
|
||||||
|
if (gamedataRoot)
|
||||||
|
return path.join(/*turbopackIgnore: true*/ gamedataRoot, "bundled/effect");
|
||||||
|
return EFFECT_NITRO_DIR_FALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEffectSwfDir(): Promise<string> {
|
||||||
|
const configured = (
|
||||||
|
(await siteSettings.get("effect_swf_dir", "")) ?? ""
|
||||||
|
).trim();
|
||||||
|
return configured || EFFECT_SWF_DIR_FALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
export async function ensureEffectDirs(): Promise<void> {
|
export async function ensureEffectDirs(): Promise<void> {
|
||||||
|
const [nitroDir, swfDir] = await Promise.all([
|
||||||
|
getEffectNitroDir(),
|
||||||
|
getEffectSwfDir(),
|
||||||
|
]);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
[EFFECT_NITRO_DIR, EFFECT_SWF_DIR]
|
[nitroDir, swfDir]
|
||||||
.filter((dir) => !existsSync(/*turbopackIgnore: true*/ dir))
|
.filter((dir) => !existsSync(/*turbopackIgnore: true*/ dir))
|
||||||
.map((dir) =>
|
.map((dir) =>
|
||||||
fs.mkdir(/*turbopackIgnore: true*/ dir, { recursive: true }),
|
fs.mkdir(/*turbopackIgnore: true*/ dir, { recursive: true }),
|
||||||
@@ -36,8 +60,11 @@ export async function ensureEffectDirs(): Promise<void> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function nitroPathFor(lib: string): string {
|
async function nitroPathFor(lib: string): Promise<string> {
|
||||||
return path.join(/*turbopackIgnore: true*/ EFFECT_NITRO_DIR, `${lib}.nitro`);
|
return path.join(
|
||||||
|
/*turbopackIgnore: true*/ await getEffectNitroDir(),
|
||||||
|
`${lib}.nitro`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function importSingleEffect(params: {
|
export async function importSingleEffect(params: {
|
||||||
@@ -51,12 +78,12 @@ export async function importSingleEffect(params: {
|
|||||||
const warnings: string[] = [];
|
const warnings: string[] = [];
|
||||||
await ensureEffectDirs();
|
await ensureEffectDirs();
|
||||||
|
|
||||||
const nitroPath = nitroPathFor(lib);
|
const nitroPath = await nitroPathFor(lib);
|
||||||
|
|
||||||
// Download SWF
|
// Download SWF
|
||||||
onProgress?.("downloading");
|
onProgress?.("downloading");
|
||||||
const swfPath = path.join(
|
const swfPath = path.join(
|
||||||
/*turbopackIgnore: true*/ EFFECT_SWF_DIR,
|
/*turbopackIgnore: true*/ await getEffectSwfDir(),
|
||||||
`${lib}.swf`,
|
`${lib}.swf`,
|
||||||
);
|
);
|
||||||
let swfUrl: string;
|
let swfUrl: string;
|
||||||
@@ -116,7 +143,7 @@ export async function deleteImportedEffect(
|
|||||||
const removed = await removeEffect(idOrLib);
|
const removed = await removeEffect(idOrLib);
|
||||||
let deletedFile = false;
|
let deletedFile = false;
|
||||||
if (entry) {
|
if (entry) {
|
||||||
const p = nitroPathFor(entry.lib);
|
const p = await nitroPathFor(entry.lib);
|
||||||
if (existsSync(/*turbopackIgnore: true*/ p)) {
|
if (existsSync(/*turbopackIgnore: true*/ p)) {
|
||||||
await fs.unlink(/*turbopackIgnore: true*/ p).catch(() => {});
|
await fs.unlink(/*turbopackIgnore: true*/ p).catch(() => {});
|
||||||
deletedFile = true;
|
deletedFile = true;
|
||||||
@@ -126,20 +153,23 @@ export async function deleteImportedEffect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getEffectList(search: string): Promise<EffectListItem[]> {
|
export async function getEffectList(search: string): Promise<EffectListItem[]> {
|
||||||
const [official, local] = await Promise.all([
|
const [official, local, nitroDir] = await Promise.all([
|
||||||
listOfficialEffects(),
|
listOfficialEffects(),
|
||||||
listLocalEffects(),
|
listLocalEffects(),
|
||||||
|
getEffectNitroDir(),
|
||||||
]);
|
]);
|
||||||
|
// The official Habbo effectmap endpoint is frequently unreachable/dead.
|
||||||
|
// Fall back to the locally cached map so the list stays usable.
|
||||||
|
const base = official.length > 0 ? official : local;
|
||||||
const localByLib = new Map(local.map((e) => [e.lib, e]));
|
const localByLib = new Map(local.map((e) => [e.lib, e]));
|
||||||
const term = search.trim().toLowerCase();
|
const term = search.trim().toLowerCase();
|
||||||
const merged = official.map((e) => {
|
const merged = base.map((e) => ({
|
||||||
const present = localByLib.has(e.lib);
|
...e,
|
||||||
return {
|
present: localByLib.has(e.lib),
|
||||||
...e,
|
nitroExists: existsSync(
|
||||||
present,
|
/*turbopackIgnore: true*/ path.join(nitroDir, `${e.lib}.nitro`),
|
||||||
nitroExists: existsSync(/*turbopackIgnore: true*/ nitroPathFor(e.lib)),
|
),
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
return term
|
return term
|
||||||
? merged.filter(
|
? merged.filter(
|
||||||
(e) =>
|
(e) =>
|
||||||
@@ -160,10 +190,16 @@ export async function getEffectStats(): Promise<{
|
|||||||
listLocalEffects(),
|
listLocalEffects(),
|
||||||
]);
|
]);
|
||||||
const localLibs = new Set(local.map((e) => e.lib));
|
const localLibs = new Set(local.map((e) => e.lib));
|
||||||
const imported = official.filter((e) => localLibs.has(e.lib)).length;
|
const imported =
|
||||||
|
official.length > 0
|
||||||
|
? official.filter((e) => localLibs.has(e.lib)).length
|
||||||
|
: localLibs.size;
|
||||||
return {
|
return {
|
||||||
official: official.length,
|
official: official.length > 0 ? official.length : local.length,
|
||||||
imported,
|
imported,
|
||||||
missing: official.length - imported,
|
missing:
|
||||||
|
official.length > 0
|
||||||
|
? official.length - imported
|
||||||
|
: local.length - imported,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ export async function getEffectMapPath(): Promise<string> {
|
|||||||
"effectmap_url",
|
"effectmap_url",
|
||||||
"/nitro-assets/gamedata/EffectMap.json",
|
"/nitro-assets/gamedata/EffectMap.json",
|
||||||
);
|
);
|
||||||
return resolveGamedataFile(
|
return await resolveGamedataFile(
|
||||||
url ?? "/nitro-assets/gamedata/EffectMap.json",
|
url ?? "/nitro-assets/gamedata/EffectMap.json",
|
||||||
"EffectMap.json",
|
"EffectMap.json",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ import { describe, expect, it, vi } from "vitest";
|
|||||||
vi.mock("@/lib/services/import/core/download", () => ({
|
vi.mock("@/lib/services/import/core/download", () => ({
|
||||||
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
downloadFile: vi.fn(async () => ({ ok: true, size: 100 })),
|
||||||
}));
|
}));
|
||||||
|
vi.mock("@/lib/services/site-settings", () => ({
|
||||||
|
siteSettings: { get: vi.fn(async () => "") },
|
||||||
|
}));
|
||||||
|
vi.mock("@/lib/services/furni-asset-dirs", () => ({
|
||||||
|
getGamedataRoot: vi.fn(async () => ""),
|
||||||
|
}));
|
||||||
vi.mock("@/lib/services/figure-source", () => ({
|
vi.mock("@/lib/services/figure-source", () => ({
|
||||||
resolveFigureSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
resolveFigureSwfUrl: vi.fn(async (lib: string) => `https://x/${lib}.swf`),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import { existsSync, promises as fs } from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { resolveFigureSwfUrl } from "@/lib/services/figure-source";
|
import { resolveFigureSwfUrl } from "@/lib/services/figure-source";
|
||||||
import { listFigureLibraries } from "@/lib/services/figuremap";
|
import { listFigureLibraries } from "@/lib/services/figuremap";
|
||||||
|
import { getGamedataRoot } from "@/lib/services/furni-asset-dirs";
|
||||||
import { downloadFile } from "@/lib/services/import/core/download";
|
import { downloadFile } from "@/lib/services/import/core/download";
|
||||||
|
import { siteSettings } from "@/lib/services/site-settings";
|
||||||
import { convertSwfToNitro } from "@/lib/services/swf-to-nitro";
|
import { convertSwfToNitro } from "@/lib/services/swf-to-nitro";
|
||||||
|
|
||||||
export interface FigureListItem {
|
export interface FigureListItem {
|
||||||
@@ -22,18 +24,40 @@ export interface ImportFigureResult {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FIGURE_NITRO_DIR = path.join(
|
const FIGURE_NITRO_DIR_FALLBACK = path.join(
|
||||||
/*turbopackIgnore: true*/ process.cwd(),
|
/*turbopackIgnore: true*/ process.cwd(),
|
||||||
"public/nitro-assets/bundled/figure",
|
"public/nitro-assets/bundled/figure",
|
||||||
);
|
);
|
||||||
export const FIGURE_SWF_DIR = path.join(
|
const FIGURE_SWF_DIR_FALLBACK = path.join(
|
||||||
/*turbopackIgnore: true*/ process.cwd(),
|
/*turbopackIgnore: true*/ process.cwd(),
|
||||||
"public/swf/gordon",
|
"public/swf/gordon",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
async function getFigureNitroDir(): Promise<string> {
|
||||||
|
const configured = (
|
||||||
|
(await siteSettings.get("figure_nitro_dir", "")) ?? ""
|
||||||
|
).trim();
|
||||||
|
if (configured) return configured;
|
||||||
|
const gamedataRoot = await getGamedataRoot();
|
||||||
|
if (gamedataRoot)
|
||||||
|
return path.join(/*turbopackIgnore: true*/ gamedataRoot, "bundled/figure");
|
||||||
|
return FIGURE_NITRO_DIR_FALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getFigureSwfDir(): Promise<string> {
|
||||||
|
const configured = (
|
||||||
|
(await siteSettings.get("figure_swf_dir", "")) ?? ""
|
||||||
|
).trim();
|
||||||
|
return configured || FIGURE_SWF_DIR_FALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
export async function ensureFigureDirs(): Promise<void> {
|
export async function ensureFigureDirs(): Promise<void> {
|
||||||
|
const [nitroDir, swfDir] = await Promise.all([
|
||||||
|
getFigureNitroDir(),
|
||||||
|
getFigureSwfDir(),
|
||||||
|
]);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
[FIGURE_NITRO_DIR, FIGURE_SWF_DIR]
|
[nitroDir, swfDir]
|
||||||
.filter((dir) => !existsSync(/*turbopackIgnore: true*/ dir))
|
.filter((dir) => !existsSync(/*turbopackIgnore: true*/ dir))
|
||||||
.map((dir) =>
|
.map((dir) =>
|
||||||
fs.mkdir(/*turbopackIgnore: true*/ dir, { recursive: true }),
|
fs.mkdir(/*turbopackIgnore: true*/ dir, { recursive: true }),
|
||||||
@@ -41,8 +65,11 @@ export async function ensureFigureDirs(): Promise<void> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function nitroPathFor(lib: string): string {
|
async function nitroPathFor(lib: string): Promise<string> {
|
||||||
return path.join(/*turbopackIgnore: true*/ FIGURE_NITRO_DIR, `${lib}.nitro`);
|
return path.join(
|
||||||
|
/*turbopackIgnore: true*/ await getFigureNitroDir(),
|
||||||
|
`${lib}.nitro`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function importSingleFigure(params: {
|
export async function importSingleFigure(params: {
|
||||||
@@ -55,7 +82,7 @@ export async function importSingleFigure(params: {
|
|||||||
|
|
||||||
onProgress?.("downloading");
|
onProgress?.("downloading");
|
||||||
const swfPath = path.join(
|
const swfPath = path.join(
|
||||||
/*turbopackIgnore: true*/ FIGURE_SWF_DIR,
|
/*turbopackIgnore: true*/ await getFigureSwfDir(),
|
||||||
`${lib}.swf`,
|
`${lib}.swf`,
|
||||||
);
|
);
|
||||||
let swfUrl: string;
|
let swfUrl: string;
|
||||||
@@ -83,7 +110,7 @@ export async function importSingleFigure(params: {
|
|||||||
const swfBuffer = await fs.readFile(/*turbopackIgnore: true*/ swfPath);
|
const swfBuffer = await fs.readFile(/*turbopackIgnore: true*/ swfPath);
|
||||||
const result = convertSwfToNitro(swfBuffer, lib);
|
const result = convertSwfToNitro(swfBuffer, lib);
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
/*turbopackIgnore: true*/ nitroPathFor(lib),
|
/*turbopackIgnore: true*/ await nitroPathFor(lib),
|
||||||
result.bundle,
|
result.bundle,
|
||||||
);
|
);
|
||||||
if (result.warnings?.length) warnings.push(...result.warnings);
|
if (result.warnings?.length) warnings.push(...result.warnings);
|
||||||
@@ -102,7 +129,7 @@ export async function importSingleFigure(params: {
|
|||||||
export async function deleteImportedFigure(
|
export async function deleteImportedFigure(
|
||||||
lib: string,
|
lib: string,
|
||||||
): Promise<{ deletedFile: boolean }> {
|
): Promise<{ deletedFile: boolean }> {
|
||||||
const p = nitroPathFor(lib);
|
const p = await nitroPathFor(lib);
|
||||||
if (existsSync(/*turbopackIgnore: true*/ p)) {
|
if (existsSync(/*turbopackIgnore: true*/ p)) {
|
||||||
await fs.unlink(/*turbopackIgnore: true*/ p).catch(() => {});
|
await fs.unlink(/*turbopackIgnore: true*/ p).catch(() => {});
|
||||||
return { deletedFile: true };
|
return { deletedFile: true };
|
||||||
@@ -126,10 +153,13 @@ export async function getFigureList(params: {
|
|||||||
: libs;
|
: libs;
|
||||||
const total = filtered.length;
|
const total = filtered.length;
|
||||||
const start = (Math.max(page, 1) - 1) * perPage;
|
const start = (Math.max(page, 1) - 1) * perPage;
|
||||||
|
const nitroDir = await getFigureNitroDir();
|
||||||
const items = filtered.slice(start, start + perPage).map((l) => ({
|
const items = filtered.slice(start, start + perPage).map((l) => ({
|
||||||
lib: l.id,
|
lib: l.id,
|
||||||
revision: l.revision,
|
revision: l.revision,
|
||||||
nitroExists: existsSync(/*turbopackIgnore: true*/ nitroPathFor(l.id)),
|
nitroExists: existsSync(
|
||||||
|
/*turbopackIgnore: true*/ path.join(nitroDir, `${l.id}.nitro`),
|
||||||
|
),
|
||||||
previewType: l.parts?.[0]?.type,
|
previewType: l.parts?.[0]?.type,
|
||||||
previewId: l.parts?.[0]?.id,
|
previewId: l.parts?.[0]?.id,
|
||||||
}));
|
}));
|
||||||
@@ -141,9 +171,12 @@ export async function getFigureStats(): Promise<{
|
|||||||
imported: number;
|
imported: number;
|
||||||
missing: number;
|
missing: number;
|
||||||
}> {
|
}> {
|
||||||
const libs = await listFigureLibraries();
|
const [libs, nitroDir] = await Promise.all([
|
||||||
|
listFigureLibraries(),
|
||||||
|
getFigureNitroDir(),
|
||||||
|
]);
|
||||||
const imported = libs.filter((l) =>
|
const imported = libs.filter((l) =>
|
||||||
existsSync(/*turbopackIgnore: true*/ nitroPathFor(l.id)),
|
existsSync(/*turbopackIgnore: true*/ path.join(nitroDir, `${l.id}.nitro`)),
|
||||||
).length;
|
).length;
|
||||||
return { total: libs.length, imported, missing: libs.length - imported };
|
return { total: libs.length, imported, missing: libs.length - imported };
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ export async function getFigureDataPath(): Promise<string> {
|
|||||||
"figuredata_url",
|
"figuredata_url",
|
||||||
"/nitro-assets/gamedata/FigureData.json",
|
"/nitro-assets/gamedata/FigureData.json",
|
||||||
);
|
);
|
||||||
return resolveGamedataFile(
|
return await resolveGamedataFile(
|
||||||
url ?? "/nitro-assets/gamedata/FigureData.json",
|
url ?? "/nitro-assets/gamedata/FigureData.json",
|
||||||
"FigureData.json",
|
"FigureData.json",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export async function getFigureMapPath(): Promise<string> {
|
|||||||
"figuremap_url",
|
"figuremap_url",
|
||||||
"/nitro-assets/gamedata/FigureMap.json",
|
"/nitro-assets/gamedata/FigureMap.json",
|
||||||
);
|
);
|
||||||
return resolveGamedataFile(
|
return await resolveGamedataFile(
|
||||||
url ?? "/nitro-assets/gamedata/FigureMap.json",
|
url ?? "/nitro-assets/gamedata/FigureMap.json",
|
||||||
"FigureMap.json",
|
"FigureMap.json",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import path from "node:path";
|
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";
|
import { resolveGamedataFile } from "./asset-paths";
|
||||||
|
|
||||||
describe("resolveGamedataFile", () => {
|
describe("resolveGamedataFile", () => {
|
||||||
it("uses absolute external paths as-is", () => {
|
it("uses absolute external paths as-is", async () => {
|
||||||
const absolutePath = path.win32.join(
|
const absolutePath = path.win32.join(
|
||||||
"E:\\",
|
"E:\\",
|
||||||
"Users",
|
"Users",
|
||||||
@@ -16,7 +21,7 @@ describe("resolveGamedataFile", () => {
|
|||||||
"FigureMap.json",
|
"FigureMap.json",
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(resolveGamedataFile(absolutePath, "FigureMap.json")).toBe(
|
expect(await resolveGamedataFile(absolutePath, "FigureMap.json")).toBe(
|
||||||
absolutePath,
|
absolutePath,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import { existsSync } from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
import path from "node:path";
|
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/,
|
// The CMS default gamedata JSON paths point under public/nitro-assets/gamedata/,
|
||||||
// but this deployment keeps the gamedata JSON (FigureMap/FigureData/EffectMap…)
|
// 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
|
// configured path is absent, so importers read AND write the real file — no
|
||||||
// manual setting required. (Bundled .nitro stay under public/nitro-assets/bundled,
|
// manual setting required. (Bundled .nitro stay under the gamedata root's
|
||||||
// the client's served asset dir — see *_NITRO_DIR consts in the import services.)
|
// `bundled/` dir, the location the Nitro client loads from.)
|
||||||
|
|
||||||
function pub(...segs: string[]): string {
|
function pub(...segs: string[]): string {
|
||||||
return path.join(/*turbopackIgnore: true*/ process.cwd(), "public", ...segs);
|
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.
|
* Resolve a gamedata JSON file from a `*_url` setting value (e.g.
|
||||||
* `/nitro-assets/gamedata/FigureMap.json`). Falls back to
|
* `/nitro-assets/gamedata/FigureMap.json`). Falls back to the deployment's
|
||||||
* `public/Gamedata/config/<fallbackName>` if the configured path is absent.
|
* gamedata root `config/` dir (then `public/Gamedata/config/`) when the
|
||||||
* Returns the configured path when neither exists (write target for fresh setups).
|
* configured path is absent. Returns the configured path when neither exists
|
||||||
|
* (write target for fresh setups).
|
||||||
*/
|
*/
|
||||||
export function resolveGamedataFile(url: string, fallbackName: string): string {
|
export async function resolveGamedataFile(
|
||||||
if (
|
url: string,
|
||||||
path.win32.isAbsolute(url) ||
|
fallbackName: string,
|
||||||
(path.isAbsolute(url) && !url.startsWith("/"))
|
): 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;
|
return url;
|
||||||
|
}
|
||||||
const configured = pub(url.replace(/^\/+/, ""));
|
const configured = pub(url.replace(/^\/+/, ""));
|
||||||
if (existsSync(/*turbopackIgnore: true*/ configured)) return configured;
|
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);
|
const gamedata = pub("Gamedata", "config", fallbackName);
|
||||||
if (existsSync(/*turbopackIgnore: true*/ gamedata)) return gamedata;
|
if (existsSync(/*turbopackIgnore: true*/ gamedata)) return gamedata;
|
||||||
return configured;
|
return configured;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ describe("staff smoke contract", () => {
|
|||||||
expect(pkg).not.toContain("prisma:generate");
|
expect(pkg).not.toContain("prisma:generate");
|
||||||
expect(pkg).toContain('"db:generate": "drizzle-kit generate"');
|
expect(pkg).toContain('"db:generate": "drizzle-kit generate"');
|
||||||
expect(pkg).toContain('"db:studio": "drizzle-kit studio"');
|
expect(pkg).toContain('"db:studio": "drizzle-kit studio"');
|
||||||
expect(pkg).toContain('"db:introspect": "drizzle-kit introspect"');
|
expect(pkg).toContain('"db:migrate": "drizzle-kit migrate"');
|
||||||
expect(readFileSync("drizzle.config.ts", "utf8")).toContain(
|
expect(readFileSync("drizzle.config.ts", "utf8")).toContain(
|
||||||
"./drizzle/drafts",
|
"./drizzle/drafts",
|
||||||
);
|
);
|
||||||
@@ -90,8 +90,10 @@ describe("staff smoke contract", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps force-dynamic only on admin/mod layouts", () => {
|
it("opts admin/mod out of static caching via instant=false", () => {
|
||||||
const hits: string[] = [];
|
// The Cache Components migration replaced `force-dynamic` with
|
||||||
|
// `export const instant = false` — the legacy export must not survive.
|
||||||
|
let legacyHits = 0;
|
||||||
function walk(dir: string) {
|
function walk(dir: string) {
|
||||||
for (const name of readdirSync(dir)) {
|
for (const name of readdirSync(dir)) {
|
||||||
const p = join(dir, name);
|
const p = join(dir, name);
|
||||||
@@ -101,17 +103,22 @@ describe("staff smoke contract", () => {
|
|||||||
if (
|
if (
|
||||||
/export\s+const\s+dynamic\s*=\s*["']force-dynamic["']/.test(src)
|
/export\s+const\s+dynamic\s*=\s*["']force-dynamic["']/.test(src)
|
||||||
) {
|
) {
|
||||||
hits.push(p.replace(/\\/g, "/"));
|
legacyHits++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
walk("src/app/admin");
|
walk("src/app/admin");
|
||||||
walk("src/app/mod");
|
walk("src/app/mod");
|
||||||
expect(hits.sort()).toEqual([
|
expect(legacyHits).toBe(0);
|
||||||
"src/app/admin/layout.tsx",
|
|
||||||
"src/app/mod/layout.tsx",
|
// Both staff layouts opt out of Cache Components (was force-dynamic).
|
||||||
]);
|
expect(readFileSync("src/app/admin/layout.tsx", "utf8")).toContain(
|
||||||
|
"export const instant = false",
|
||||||
|
);
|
||||||
|
expect(readFileSync("src/app/mod/layout.tsx", "utf8")).toContain(
|
||||||
|
"export const instant = false",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("caches analytics via redisCache", () => {
|
it("caches analytics via redisCache", () => {
|
||||||
|
|||||||
Reference in new issue
Block a user