From 632cef35e53fddd69d3c91d40de45a03ad56c7bb Mon Sep 17 00:00:00 2001 From: Joywayer Date: Sun, 28 Jun 2026 16:47:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(framework):=20config=20=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=94=A8=20HttpConfigFetcher(=E5=85=A8=E5=B1=80=20fetch)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../framework/config/remote-config-fetcher.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 cocoscreator_projects/YouleNexus/assets/framework/config/remote-config-fetcher.ts 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}`); + } + } +}