Files
Wrangler-API/src/platforms/gal/ZeroFive.ts
Jurangren 83661b404a feat: 初始化项目,支持流式搜索与限流
*   初始化项目结构,包括配置、依赖和忽略文件。
*   引入核心搜索逻辑,支持流式响应以提供实时进度。
*   抽象化平台接口,并集成多个Galgame和补丁搜索源。
*   实现基于IP的速率限制功能,利用Cloudflare KV存储。
*   新增自动化脚本,用于生成平台索引文件。
*   统一HTTP请求客户端,增加超时和自定义User-Agent。
*   为部分平台添加了对`zypassword`参数的支持。
2025-08-21 21:22:54 +08:00

82 lines
1.8 KiB
TypeScript

import { fetchClient } from "../../utils/httpClient";
import type { Platform, PlatformSearchResult, SearchResultItem } from "../../types";
const API_URL = "https://05fx.022016.xyz/api/fs/search";
const BASE_URL = "https://05fx.022016.xyz";
interface ZeroFiveItem {
name: string;
parent: string;
}
interface ZeroFiveResponse {
message: string;
data: {
content: ZeroFiveItem[];
total: number;
};
}
async function searchZeroFive(game: string): Promise<PlatformSearchResult> {
const searchResult: PlatformSearchResult = {
name: "05的资源小站",
count: 0,
items: [],
};
try {
const payload = {
parent: "/",
keywords: game,
scope: 0,
page: 1,
per_page: 999999, // Corresponds to MAX_RESULTS
password: "",
};
const response = await fetchClient(API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`API response status code is ${response.status}`);
}
const data = await response.json() as ZeroFiveResponse;
if (data.message !== "success") {
throw new Error(`API returned an error: ${data.message}`);
}
const items: SearchResultItem[] = data.data.content.map(item => ({
name: item.name.trim(),
url: BASE_URL + item.parent + "/" + item.name,
}));
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 ZeroFive: Platform = {
name: "05的资源小站",
color: "lime",
magic: false,
search: searchZeroFive,
};
export default ZeroFive;