From a3b9c3a75150e3dd54e842ce451b57403c995a33 Mon Sep 17 00:00:00 2001 From: Jurangren Date: Sat, 23 Aug 2025 01:36:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=202dfan=20=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=8F=8A=E5=AD=97=E7=AC=A6=E8=BD=AC=E4=B9=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 调整 2dfan API 响应处理方式,直接读取 HTML 文本而非解析 JSON。 * 在 VikaACG 中处理 2dfan 结果 HTML 中的转义字符,确保正则表达式正确匹配。 * 移除或调整了部分调试日志输出,以保持代码整洁。 --- src/platforms/gal/VikaACG.ts | 8 +------- src/platforms/patch/TWOdfan.ts | 11 +++-------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/platforms/gal/VikaACG.ts b/src/platforms/gal/VikaACG.ts index ebc1575..6343b7d 100644 --- a/src/platforms/gal/VikaACG.ts +++ b/src/platforms/gal/VikaACG.ts @@ -48,14 +48,8 @@ async function searchVikaACG(game: string): Promise { // The response is a JSON-encoded string containing HTML. // .json() will parse the JSON and unescape the string content. const html: string = await response.text(); - - console.log(JSON.stringify({ - message: "2dfan API HTML Response", - html: html, - level: "info", - })); - const matches = html.matchAll(REGEX); + const matches = html.replaceAll('\\/', '/').replaceAll('\\\\', '\\').matchAll(REGEX); const items: SearchResultItem[] = []; for (const match of matches) { diff --git a/src/platforms/patch/TWOdfan.ts b/src/platforms/patch/TWOdfan.ts index d4fb0d1..2bcece6 100644 --- a/src/platforms/patch/TWOdfan.ts +++ b/src/platforms/patch/TWOdfan.ts @@ -5,10 +5,6 @@ const API_URL = "https://2dfan.com/subjects/search"; const BASE_URL = "https://2dfan.com"; const REGEX = /

(?.*?)<\/a><\/h4>/gs; -interface TwoDFanResponse { - subjects: string; // This is an HTML string -} - async function searchTWOdfan(game: string): Promise { const searchResult: PlatformSearchResult = { name: "2dfan", @@ -25,14 +21,13 @@ async function searchTWOdfan(game: string): Promise { throw new Error(`资源平台 SearchAPI 响应异常状态码 ${response.status}`); } + const html: string = await response.text(); + console.log(JSON.stringify({ message: "2dfan API HTML Response", - html: response.text(), + html: html, level: "info", })); - - const data = await response.json() as TwoDFanResponse; - const html = data.subjects; const matches = html.matchAll(REGEX);