fix: 修复 2dfan 平台搜索结果解析及字符转义问题

*   调整 2dfan API 响应处理方式,直接读取 HTML 文本而非解析 JSON。
*   在 VikaACG 中处理 2dfan 结果 HTML 中的转义字符,确保正则表达式正确匹配。
*   移除或调整了部分调试日志输出,以保持代码整洁。
This commit is contained in:
Jurangren
2025-08-23 01:36:48 +08:00
parent 6d16623f36
commit a3b9c3a751
2 changed files with 4 additions and 15 deletions

View File

@@ -48,14 +48,8 @@ async function searchVikaACG(game: string): Promise<PlatformSearchResult> {
// 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) {

View File

@@ -5,10 +5,6 @@ const API_URL = "https://2dfan.com/subjects/search";
const BASE_URL = "https://2dfan.com";
const REGEX = /<h4 class="media-heading"><a target="_blank" href="(?<URL>.*?)">(?<NAME>.*?)<\/a><\/h4>/gs;
interface TwoDFanResponse {
subjects: string; // This is an HTML string
}
async function searchTWOdfan(game: string): Promise<PlatformSearchResult> {
const searchResult: PlatformSearchResult = {
name: "2dfan",
@@ -25,14 +21,13 @@ async function searchTWOdfan(game: string): Promise<PlatformSearchResult> {
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);