feat(framework): config resolveBootstrap 接入 mode + release 锁死 URL 覆盖
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,10 +3,12 @@ import { resolveIdentity } from './identity.ts';
|
||||
import { BUILD_IDENTITY } from './sources/defaults.ts';
|
||||
import { queryStringSource } from './sources/query-string.ts';
|
||||
import { nativeSettingsSource, type NativeHost } from './sources/native-settings.ts';
|
||||
import { resolveActiveProfile, DEFAULT_GAMESERVER, type DebugProfile } from './profiles.ts';
|
||||
import { resolveActiveProfile, PROFILES, DEFAULT_GAMESERVER, type DebugProfile } from './profiles.ts';
|
||||
import { resolveServers, type ConfigFetcher, type RemoteConfig, ConfigFetchError } from './remote-config.ts';
|
||||
import type { RuntimeMode } from './runtime-mode.ts';
|
||||
|
||||
export interface BootstrapOptions {
|
||||
mode: RuntimeMode; // 运行模式(由 resolveRuntimeMode 得到)
|
||||
win: NativeHost; // 原生注入宿主(≈ window)
|
||||
search: string; // location.search
|
||||
fetcher: ConfigFetcher; // 远程配置抓取
|
||||
@@ -16,39 +18,50 @@ export interface BootstrapOptions {
|
||||
}
|
||||
|
||||
export interface BootstrapResult {
|
||||
mode: RuntimeMode;
|
||||
isDebugger: boolean; // = (mode === 'debug')
|
||||
identity: ChannelIdentity;
|
||||
servers: string[];
|
||||
rawConfig: RemoteConfig | null;
|
||||
profile: DebugProfile;
|
||||
}
|
||||
|
||||
/** 启动编排:解析身份 + 决定服务器,产出可喂 NetClient 的结果。 */
|
||||
/** 启动编排:按运行模式解析身份 + 决定服务器,产出可喂 NetClient 的结果。 */
|
||||
export async function resolveBootstrap(opts: BootstrapOptions): Promise<BootstrapResult> {
|
||||
const profile = resolveActiveProfile(opts.search);
|
||||
const runtime = opts.isNative ? nativeSettingsSource(opts.win) : queryStringSource(opts.search);
|
||||
const identity = resolveIdentity([
|
||||
() => BUILD_IDENTITY,
|
||||
runtime,
|
||||
() => profile.identity ?? {},
|
||||
queryStringSource(opts.search), // 显式 URL 覆盖(最高)
|
||||
]);
|
||||
const isDebug = opts.mode === 'debug';
|
||||
|
||||
// 服务器决策:profile 显式 server 直连捷径
|
||||
// 模式决定 profile 与身份来源:release 强制 prod,且身份只走原生(绝不读 URL)。
|
||||
const profile = isDebug ? resolveActiveProfile(opts.search) : PROFILES.prod;
|
||||
const identity = isDebug
|
||||
? resolveIdentity([
|
||||
() => BUILD_IDENTITY,
|
||||
opts.isNative ? nativeSettingsSource(opts.win) : queryStringSource(opts.search),
|
||||
() => profile.identity ?? {},
|
||||
queryStringSource(opts.search), // 显式 URL 覆盖(最高)
|
||||
])
|
||||
: resolveIdentity([
|
||||
() => BUILD_IDENTITY,
|
||||
nativeSettingsSource(opts.win), // release:身份只取原生,URL 一律无效
|
||||
]);
|
||||
|
||||
const resultBase = { mode: opts.mode, isDebugger: isDebug, identity, profile };
|
||||
|
||||
// 服务器决策:profile 显式 server 直连捷径(仅 debug 的 local/lab 等档位会有)
|
||||
if (profile.server) {
|
||||
return { identity, servers: [profile.server], rawConfig: null, profile };
|
||||
return { ...resultBase, servers: [profile.server], rawConfig: null };
|
||||
}
|
||||
|
||||
// 否则远程配置
|
||||
const base = profile.gameserver ?? DEFAULT_GAMESERVER;
|
||||
const gameserver = profile.gameserver ?? DEFAULT_GAMESERVER;
|
||||
const bust = opts.cacheBust ? opts.cacheBust() : String(Date.now());
|
||||
const url = base + '?' + bust; // 防缓存,等价原 min_timestamp/ifast_random
|
||||
const url = gameserver + '?' + bust; // 防缓存,等价原 min_timestamp/ifast_random
|
||||
|
||||
let config: RemoteConfig;
|
||||
try {
|
||||
config = await opts.fetcher.fetch(url);
|
||||
} catch {
|
||||
if (opts.fallbackServers && opts.fallbackServers.length) {
|
||||
return { identity, servers: opts.fallbackServers, rawConfig: null, profile };
|
||||
return { ...resultBase, servers: opts.fallbackServers, rawConfig: null };
|
||||
}
|
||||
throw new ConfigFetchError(`远程配置抓取失败: ${url}`);
|
||||
}
|
||||
@@ -57,5 +70,5 @@ export async function resolveBootstrap(opts: BootstrapOptions): Promise<Bootstra
|
||||
if (!servers.length && opts.fallbackServers && opts.fallbackServers.length) {
|
||||
servers = opts.fallbackServers;
|
||||
}
|
||||
return { identity, servers, rawConfig: config, profile };
|
||||
return { ...resultBase, servers, rawConfig: config };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user