优化 KunGalgameBuDingItem 接口,支持多语言名称解析

This commit is contained in:
DRG
2025-12-23 13:03:23 +08:00
parent f6367f8304
commit 324fdb8453

View File

@@ -6,7 +6,7 @@ const BASE_URL = "https://www.moyu.moe/patch/";
interface KunGalgameBuDingItem { interface KunGalgameBuDingItem {
id: number; id: number;
name: string; name?: Record<string, string | undefined> | string;
} }
interface KunGalgameBuDingResponse { interface KunGalgameBuDingResponse {
@@ -45,10 +45,23 @@ async function searchKunGalgameBuDing(game: string): Promise<PlatformSearchResul
const data = await response.json() as KunGalgameBuDingResponse; const data = await response.json() as KunGalgameBuDingResponse;
const items: SearchResultItem[] = data.galgames.map(item => ({ const items: SearchResultItem[] = data.galgames.map(item => {
name: item.name, const nameByLocale = typeof item.name === "object" && item.name !== null
url: `${BASE_URL}${item.id}/introduction`, ? item.name
})); : undefined;
const localizedName = nameByLocale
? (nameByLocale["zh-cn"]
|| nameByLocale["ja-jp"]
|| nameByLocale["en-us"])
: undefined;
const name = (localizedName && localizedName.trim())
|| (typeof item.name === "string" ? item.name : "");
return {
name,
url: `${BASE_URL}${item.id}/introduction`,
};
});
searchResult.items = items; searchResult.items = items;
searchResult.count = items.length; searchResult.count = items.length;