feat: 引入搜索日志和增强错误提示

*   移除旧版速率限制机制,简化服务部署与维护。(频率限制转移到CloudFlare中设置防护规则)
*   新增Cloudflare日志记录功能,提升搜索过程可观测性。
*   统一并细化了各资源平台的API错误响应信息。
*   修复Koyso和真红小站的URL编码及正则匹配问题。
*   优化紫缘社的访问密码错误提示。
This commit is contained in:
Jurangren
2025-08-22 00:24:39 +08:00
parent 83661b404a
commit 6a799ee897
34 changed files with 80 additions and 99 deletions

View File

@@ -32,10 +32,27 @@ export async function fetchClient(
return response;
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
throw new Error(`Request timed out after ${TIMEOUT_SECONDS} seconds`);
throw new Error(`资源平台 SearchAPI 请求超时`);
}
throw error;
} finally {
clearTimeout(timeoutId);
}
}
/**
* 向 Cloudflare 发送日志。
* @param data 要记录的数据对象。
*/
export async function logToCF(data: object) {
try {
await fetch("https://log.gal.homes", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
} catch (error) {
console.error("Failed to log to Cloudflare:", error);
}
}