diff --git a/src/core.ts b/src/core.ts index 64519c7..d12c6bd 100644 --- a/src/core.ts +++ b/src/core.ts @@ -14,13 +14,11 @@ function formatStreamEvent(data: object): string { * @param game 要搜索的游戏名称。 * @param platforms 要使用的平台列表。 * @param writer 用于写入 SSE 事件的 WritableStreamDefaultWriter。 - * @param zypassword (可选) 访问某些平台可能需要的密码。 */ export async function handleSearchRequestStream( game: string, platforms: Platform[], writer: WritableStreamDefaultWriter, - zypassword: string = "" // 添加 zypassword 参数 ): Promise { // 记录搜索关键词 console.log(JSON.stringify({ @@ -36,8 +34,7 @@ export async function handleSearchRequestStream( const searchPromises = platforms.map(async (platform) => { try { - // 传递 zypassword 给平台搜索函数 - const result = await platform.search(game, zypassword); + const result = await platform.search(game); completed++; const progress: StreamProgress = { completed, total }; diff --git a/src/index.ts b/src/index.ts index 99e6e60..1603ac1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,6 @@ async function handleSearch(request: Request, env: Env, ctx: ExecutionContext, p try { const formData = await request.formData(); const game = formData.get("game") as string; - const zypassword = formData.get("zypassword") as string || ""; // 获取 zypassword if (!game || typeof game !== 'string') { @@ -27,7 +26,7 @@ async function handleSearch(request: Request, env: Env, ctx: ExecutionContext, p // 将异步任务交给 waitUntil 来处理,确保它能完整执行 ctx.waitUntil( - handleSearchRequestStream(game.trim(), platforms, writer, zypassword) // 传递 zypassword + handleSearchRequestStream(game.trim(), platforms, writer) .catch(err => console.error("Streaming error:", err)) .finally(() => writer.close()) ); diff --git a/src/platforms/gal/ZiYuanShe.ts b/src/platforms/gal/ZiYuanShe.ts index 0f7fe30..1d66e7a 100644 --- a/src/platforms/gal/ZiYuanShe.ts +++ b/src/platforms/gal/ZiYuanShe.ts @@ -1,69 +1,48 @@ import { fetchClient } from "../../utils/httpClient"; import type { Platform, PlatformSearchResult, SearchResultItem } from "../../types"; -const API_URL = "https://galzy.eu.org/api/fs/search"; const BASE_URL = "https://galzy.eu.org"; -interface ZiYuanSheItem { - name: string; - parent: string; -} - -interface ZiYuanSheResponse { - message: string; - data: { - content: ZiYuanSheItem[]; - total: number; - }; -} - -async function searchZiYuanShe(game: string, zypassword: string = ""): Promise { +async function searchZiYuanShe(game: string): Promise { const searchResult: PlatformSearchResult = { - name: "紫缘Gal", + name: "紫缘社", count: 0, items: [], }; try { - const payload = { - parent: "/", - keywords: game, - scope: 0, - page: 1, - per_page: 999999, // Corresponds to MAX_RESULTS - password: zypassword, // Pass the zypassword here - }; - - const response = await fetchClient(API_URL, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(payload), - }); + const response = await fetchClient(`${BASE_URL}/search?q=${encodeURIComponent(game)}`); if (!response.ok) { throw new Error(`资源平台 SearchAPI 响应异常状态码 ${response.status}`); } - const data = await response.json() as ZiYuanSheResponse; + const html = await response.text(); + const tempContent = html.split('')[0]; + const cleanedScriptContent = scriptContent.substring(scriptContent.indexOf(':') + 1).replace(/\\"/g, '"'); + const jsonData = JSON.parse(cleanedScriptContent); + + const gameListData = jsonData[3].children[2][3].gameListData.hits; - if (data.message !== "success") { - throw new Error(`${data.message}`); + if (gameListData) { + const items: SearchResultItem[] = gameListData.map((item: any) => ({ + name: (() => { + const zhTitle = item.titles.find((title: any) => title.lang === 'zh-Hans'); + const jaTitle = item.titles.find((title: any) => title.lang === 'ja'); + if (zhTitle) { + return zhTitle.title; + } + if (jaTitle) { + return jaTitle.title; + } + return item.titles[0]?.title || ''; + })(), + url: `${BASE_URL}/${item.id}`, + })); + searchResult.items = items; + searchResult.count = items.length; } - - if (data.data.total !== data.data.content.length) { - throw new Error("访问密码错误"); - } - - 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; @@ -77,8 +56,8 @@ async function searchZiYuanShe(game: string, zypassword: string = ""): Promise