From 37f47f981a29701b18c16640634909db15a2670e Mon Sep 17 00:00:00 2001 From: Jurangren Date: Sat, 23 Aug 2025 00:21:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BE=93=E5=87=BA=E6=96=B9=E5=BC=8F=E5=B9=B6=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=86=97=E4=BD=99=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 移除 `src/utils/httpClient.ts` 中自定义的 `logToCF` 日志函数。 * 将 `src/core.ts` 中所有 `logToCF` 调用替换为 `console.log` 进行结构化日志输出。 * 删除 `src/platforms/gal/xxacg.ts` 中无匹配项但存在 HTML 的特定错误检查。 --- src/core.ts | 13 ++++++------- src/platforms/gal/xxacg.ts | 5 ----- src/utils/httpClient.ts | 19 ------------------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/core.ts b/src/core.ts index ca9d87d..64519c7 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,4 +1,3 @@ -import { logToCF } from "./utils/httpClient"; import type { Platform, PlatformSearchResult, StreamProgress, StreamResult } from "./types"; import platformsGal from "./platforms/gal"; import platformsPatch from "./platforms/patch"; @@ -24,10 +23,10 @@ export async function handleSearchRequestStream( zypassword: string = "" // 添加 zypassword 参数 ): Promise { // 记录搜索关键词 - logToCF({ + console.log(JSON.stringify({ message: `搜索关键词: ${game}`, level: "info", - }); + })); const encoder = new TextEncoder(); const total = platforms.length; let completed = 0; @@ -46,10 +45,10 @@ export async function handleSearchRequestStream( if (result.count > 0 || result.error) { if (result.error) { // 记录平台错误 - logToCF({ + console.log(JSON.stringify({ message: `平台 ${result.name} 搜索错误: ${result.error}`, level: "error", - }); + })); } const streamResult: StreamResult = { name: result.name, @@ -67,10 +66,10 @@ export async function handleSearchRequestStream( // 记录平台内部的未知错误 console.error(`Error searching platform ${platform.name}:`, e); // 记录平台内部的未知错误 - logToCF({ + console.log(JSON.stringify({ message: `平台 ${platform.name} 内部错误: ${e instanceof Error ? e.message : String(e)}`, level: "error", - }); + })); const progress: StreamProgress = { completed, total }; await writer.write(encoder.encode(formatStreamEvent({ progress }))); } diff --git a/src/platforms/gal/xxacg.ts b/src/platforms/gal/xxacg.ts index c5f2314..1f762cb 100644 --- a/src/platforms/gal/xxacg.ts +++ b/src/platforms/gal/xxacg.ts @@ -38,11 +38,6 @@ async function searchXxacg(game: string): Promise { } } - if (items.length === 0 && html.length > 0) { - // 如果没有匹配项,但我们确实收到了 HTML,这可能意味着页面结构已更改。 - // 将部分 HTML 包含在错误中以供调试。 - throw new Error(`No matches found on page. HTML starts with: ${html.substring(0, 500)}`); - } searchResult.items = items; searchResult.count = items.length; diff --git a/src/utils/httpClient.ts b/src/utils/httpClient.ts index 4fcf320..81da63f 100644 --- a/src/utils/httpClient.ts +++ b/src/utils/httpClient.ts @@ -38,23 +38,4 @@ export async function fetchClient( } finally { clearTimeout(timeoutId); } -} -/** - * 向 Cloudflare 发送日志。 - * @param data 要记录的数据对象。 - */ -export async function logToCF(data: object) { - // 在此处添加 console.log,以便在 Cloudflare 控制台也能看到日志 - console.log(JSON.stringify(data)); - try { - await fetch("https://log.gal.homes", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(data), - }); - } catch (error) { - console.error("Failed to log to Cloudflare:", error); - } } \ No newline at end of file