From 6a59d03ac063632b46a029cb9981f679d4b06cf8 Mon Sep 17 00:00:00 2001 From: Jurangren Date: Fri, 22 Aug 2025 01:30:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E8=BF=9BVikaACG=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=A7=A3=E6=9E=90=E5=B9=B6=E8=B0=83=E6=95=B42dfan?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复VikaACG平台HTML解析正则表达式中的结束标签错误。 * 简化VikaACG API响应的处理流程,直接使用文本内容。 * 调整2dfan平台日志输出,在JSON解析前显示原始响应文本。 --- src/platforms/gal/VikaACG.ts | 73 +++++++++++++--------------------- src/platforms/patch/TWOdfan.ts | 4 +- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/platforms/gal/VikaACG.ts b/src/platforms/gal/VikaACG.ts index 22efcb5..a6e9d8b 100644 --- a/src/platforms/gal/VikaACG.ts +++ b/src/platforms/gal/VikaACG.ts @@ -2,11 +2,7 @@ import { fetchClient } from "../../utils/httpClient"; import type { Platform, PlatformSearchResult, SearchResultItem } from "../../types"; const API_URL = "https://www.vikacg.com/wp-json/b2/v1/getPostList"; - -// The Python code suggests the response text itself might be a JSON string -// that contains escaped HTML. Let's try to parse it as JSON first. -// The regex is applied to the *unescaped* string. -const REGEX = /

(?.*?)<"/gs; +const REGEX = /

(?.*?)<\/a>/gs; async function searchVikaACG(game: string): Promise { const searchResult: PlatformSearchResult = { @@ -16,57 +12,44 @@ async function searchVikaACG(game: string): Promise { }; try { - const payload = { - paged: 1, - post_paged: 1, - post_count: 1000, // Corresponds to MAX_RESULTS - post_type: "post-1", - post_cat: [6], - post_order: "modified", - post_meta: [ - "user", "date", "des", "cats", "like", "comment", "views", "video", "download", "hide", - ], - metas: {}, - search: game, - }; - const response = await fetchClient(API_URL, { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify(payload), + body: JSON.stringify({ + paged: 1, + post_paged: 1, + post_count: 1000, // Hardcoded limit, larger values may cause timeouts + post_type: "post-1", + post_cat: [6], + post_order: "modified", + post_meta: [ + "user", + "date", + "des", + "cats", + "like", + "comment", + "views", + "video", + "download", + "hide", + ], + metas: {}, + search: game, + }), }); if (!response.ok) { throw new Error(`资源平台 SearchAPI 响应异常状态码 ${response.status}`); } - const rawText = await response.text(); - let htmlContent: string; - - try { - // Attempt to parse as JSON first. If it's a JSON string containing HTML, - // JSON.parse will handle standard escapes like \uXXXX. - const parsedJson = JSON.parse(rawText); - // Assuming the HTML content is directly the value of the JSON, or a specific field. - // The Python code implies the entire response text, after unescaping, is the HTML. - // So, if parsedJson is a string, use it. Otherwise, stringify it. - htmlContent = typeof parsedJson === 'string' ? parsedJson : JSON.stringify(parsedJson); - } catch (jsonError) { - // If JSON.parse fails, it might be due to non-standard Python escapes like \\/ or \\\\ - // Attempt a simple unescape for these specific cases. - // Note: This is a simplified unescape and might not cover all Python's unicode_escape nuances. - const unescapedText = rawText.replace(/\\(.)/g, '$1'); // Replaces \\/ with / and \\\\ with \ - try { - htmlContent = JSON.parse(unescapedText); // Try parsing as JSON again - } catch (finalError) { - // If still fails, assume it's raw HTML that just needs basic unescaping - htmlContent = unescapedText; - } - } - - const matches = htmlContent.matchAll(REGEX); + // 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(); + + const matches = html.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 5ba5a12..c445f12 100644 --- a/src/platforms/patch/TWOdfan.ts +++ b/src/platforms/patch/TWOdfan.ts @@ -25,10 +25,10 @@ async function searchTWOdfan(game: string): Promise { throw new Error(`资源平台 SearchAPI 响应异常状态码 ${response.status}`); } + console.log("2dfan API HTML Response:", response.text()); + const data = await response.json() as TwoDFanResponse; const html = data.subjects; - - console.log("2dfan API HTML Response:", html); const matches = html.matchAll(REGEX);