You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 15:06:20 +00:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user