Files
Wrangler-API/src/platforms/gal/GalgameX.ts
Jurangren 4d93d1b3e1 feat: 引入平台标签系统,优化平台信息及错误日志
- 引入平台标签系统,提供详细的平台特性说明。
- 重构搜索结果初始化,避免平台名称重复定义。
- 修正核心搜索错误日志,确保正确记录平台名称。
- 移除两个Galgame平台:TianYouErCiYuan(收费)和YingZhiGuang(网站转型)。
- 更新部分平台的颜色、魔法属性和标签信息。
2025-10-06 22:09:13 +08:00

83 lines
2.0 KiB
TypeScript

import { fetchClient } from "../../utils/httpClient";
import type { Platform, PlatformSearchResult, SearchResultItem } from "../../types";
const API_URL = "https://www.galgamex.net/api/search";
const BASE_URL = "https://www.galgamex.net/";
interface GalgameXItem {
name: string;
uniqueId: string;
}
interface GalgameXResponse {
galgames: GalgameXItem[];
}
async function searchGalgameX(game: string): Promise<PlatformSearchResult> {
const searchResult: PlatformSearchResult = {
count: 0,
items: [],
};
try {
const payload = {
queryString: JSON.stringify([{ type: "keyword", name: game }]),
limit: 24, // Hardcoded as per original script
searchOption: {
searchInIntroduction: false,
searchInAlias: true,
searchInTag: false,
},
page: 1,
selectedType: "all",
selectedLanguage: "all",
selectedPlatform: "all",
sortField: "resource_update_time",
sortOrder: "desc",
selectedYears: ["all"],
selectedMonths: ["all"],
};
const response = await fetchClient(API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`资源平台 SearchAPI 响应异常状态码 ${response.status}`);
}
const data = await response.json() as GalgameXResponse;
const items: SearchResultItem[] = data.galgames.map(item => ({
name: item.name.trim(),
url: BASE_URL + item.uniqueId,
}));
searchResult.items = items;
searchResult.count = items.length;
} catch (error) {
if (error instanceof Error) {
searchResult.error = error.message;
} else {
searchResult.error = "An unknown error occurred";
}
searchResult.count = -1;
}
return searchResult;
}
const GalgameX: Platform = {
name: "Galgamex",
color: "lime",
tags: ["NoReq", "SuDrive"],
magic: false,
search: searchGalgameX,
};
export default GalgameX;