perf(gamedata): manifest ext by JSON mode, no double-probe

tryFetchManifestPair sceglie l'estensione in base a resolveJsonMode():
json5 -> .json5, legacy -> .json, auto -> entrambi. Evita le richieste
manifest.json fallite a ogni avvio in modalita json5.
This commit is contained in:
medievalshell
2026-05-30 00:14:44 +02:00
parent b127501c52
commit c3b15f02bf
2 changed files with 14 additions and 4 deletions
+13 -3
View File
@@ -1,4 +1,4 @@
import { ConfigJsonError, fetchConfigJson, isMissingResource } from './JsonParser';
import { ConfigJsonError, fetchConfigJson, isMissingResource, resolveJsonMode } from './JsonParser';
import { NitroLogger } from './NitroLogger';
export const DEFAULT_TIERS = [ 'core', 'custom', 'seasonal' ] as const;
@@ -45,10 +45,20 @@ const tryFetchManifest = async <T = any>(url: string): Promise<T | null> =>
}
};
// Try .json5 first, then .json — both treated as optional. Anything other
// than 404 on either bubbles up.
// Pick the manifest extension from the active JSON mode instead of always
// probing both — that just doubles the failed requests on startup.
// json5 -> only <name>.json5
// legacy -> only <name>.json
// auto -> try .json5 first, fall back to .json
// All treated as optional (a clean 404 -> null); anything else bubbles up.
const tryFetchManifestPair = async <T = any>(baseUrl: string, name: string): Promise<T | null> =>
{
const mode = resolveJsonMode();
if(mode === 'json5') return tryFetchManifest<T>(joinUrl(baseUrl, `${ name }.json5`));
if(mode === 'legacy') return tryFetchManifest<T>(joinUrl(baseUrl, `${ name }.json`));
const json5 = await tryFetchManifest<T>(joinUrl(baseUrl, `${ name }.json5`));
if(json5 !== null) return json5;
+1 -1
View File
@@ -27,7 +27,7 @@ export class ConfigJsonError extends Error
export const isMissingResource = (err: unknown): boolean =>
err instanceof ConfigJsonError && err.phase === 'fetch' && err.httpStatus === 404;
const resolveJsonMode = (): 'legacy' | 'json5' | 'auto' =>
export const resolveJsonMode = (): 'legacy' | 'json5' | 'auto' =>
{
try
{