mirror of
https://github.com/Moe-Sakura/Wrangler-API.git
synced 2026-03-19 04:59:46 +08:00
- 引入平台标签系统,提供详细的平台特性说明。 - 重构搜索结果初始化,避免平台名称重复定义。 - 修正核心搜索错误日志,确保正确记录平台名称。 - 移除两个Galgame平台:TianYouErCiYuan(收费)和YingZhiGuang(网站转型)。 - 更新部分平台的颜色、魔法属性和标签信息。
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { fetchClient } from "../../utils/httpClient";
|
|
import type { Platform, PlatformSearchResult, SearchResultItem } from "../../types";
|
|
|
|
const API_URL = "https://www.hikarinagi.net/";
|
|
const REGEX = /" class="lazyload fit-cover radius8">.*?<h2 class="item-heading"><a target="_blank" href="(?<URL>.*?)">(?<NAME>.*?)<\/a><\/h2>/gs;
|
|
|
|
async function searchHikarinagi(game: string): Promise<PlatformSearchResult> {
|
|
const searchResult: PlatformSearchResult = {
|
|
count: 0,
|
|
items: [],
|
|
};
|
|
|
|
try {
|
|
const url = new URL(API_URL);
|
|
url.searchParams.set("s", game);
|
|
|
|
const response = await fetchClient(url);
|
|
if (!response.ok) {
|
|
throw new Error(`资源平台 SearchAPI 响应异常状态码 ${response.status}`);
|
|
}
|
|
|
|
const html = await response.text();
|
|
const matches = html.matchAll(REGEX);
|
|
|
|
const items: SearchResultItem[] = [];
|
|
for (const match of matches) {
|
|
if (match.groups?.NAME && match.groups?.URL) {
|
|
items.push({
|
|
name: match.groups.NAME.trim(),
|
|
url: match.groups.URL,
|
|
});
|
|
}
|
|
}
|
|
|
|
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 Hikarinagi: Platform = {
|
|
name: "Hikarinagi",
|
|
color: "white",
|
|
tags: ["LoginPay", "SuDrive"],
|
|
magic: false,
|
|
search: searchHikarinagi,
|
|
};
|
|
|
|
export default Hikarinagi; |