diff --git a/cocoscreator_projects/YouleNexus/assets/framework/config/remote-config-fetcher.ts b/cocoscreator_projects/YouleNexus/assets/framework/config/remote-config-fetcher.ts new file mode 100644 index 0000000..6dea9a3 --- /dev/null +++ b/cocoscreator_projects/YouleNexus/assets/framework/config/remote-config-fetcher.ts @@ -0,0 +1,15 @@ +import type { ConfigFetcher, RemoteConfig } from './remote-config.ts'; +import { ConfigParseError } from './remote-config.ts'; + +/** 生产用 ConfigFetcher:全局 fetch 抓取远程配置 txt 并 JSON.parse。 */ +export class HttpConfigFetcher implements ConfigFetcher { + async fetch(url: string): Promise { + const resp = await fetch(url, { method: 'GET' }); + const text = await resp.text(); + try { + return JSON.parse(text) as RemoteConfig; + } catch { + throw new ConfigParseError(`远程配置 JSON 解析失败: ${url}`); + } + } +}