feat: 初始化项目,支持流式搜索与限流

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

41
src/utils/httpClient.ts Normal file
View File

@@ -0,0 +1,41 @@
const TIMEOUT_SECONDS = 15;
const HEADERS = {
"Connection": "close",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 (From SearchGal.homes) (https://github.com/Moe-Sakura/SearchGal)",
};
/**
* 一个封装了原生 fetch 并增加了超时功能的 HTTP 客户端。
* @param url 请求的 URL。
* @param options fetch 的请求选项。
* @returns 返回一个 Promise<Response>。
*/
export async function fetchClient(
url: string | URL,
options: RequestInit = {}
): Promise<Response> {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_SECONDS * 1000);
const finalOptions: RequestInit = {
...options,
headers: {
...HEADERS,
...options.headers,
},
signal: controller.signal,
};
try {
const response = await fetch(url, finalOptions);
return response;
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
throw new Error(`Request timed out after ${TIMEOUT_SECONDS} seconds`);
}
throw error;
} finally {
clearTimeout(timeoutId);
}
}