mirror of
https://github.com/Moe-Sakura/Wrangler-API.git
synced 2026-03-15 04:13:18 +08:00
refactor: 统一日志输出方式并移除冗余检查
* 移除 `src/utils/httpClient.ts` 中自定义的 `logToCF` 日志函数。 * 将 `src/core.ts` 中所有 `logToCF` 调用替换为 `console.log` 进行结构化日志输出。 * 删除 `src/platforms/gal/xxacg.ts` 中无匹配项但存在 HTML 的特定错误检查。
This commit is contained in:
13
src/core.ts
13
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<void> {
|
||||
// 记录搜索关键词
|
||||
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 })));
|
||||
}
|
||||
|
||||
@@ -38,11 +38,6 @@ async function searchXxacg(game: string): Promise<PlatformSearchResult> {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user